diff --git a/CONFIG.md b/CONFIG.md index 39dec2bd..409511a4 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -74,6 +74,18 @@ Choose if your CPU supports the Commodore Semiconductor Group 65CE02 instruction It enables some speed/size code optimizations. +### `CONFIG_CPU_CSG_4510` + +Choose if your CPU supports the Commodore Semiconductor Group 4510 instruction set, like: + +* CSG 4510 - microcontroller used in the Commodore 65 prototypes + +It enables some speed/size code optimizations and allows C65 memory mapping to work. + +### `CONFIG_CPU_M65_45GS02` + +Choose if you have a Mega65 FPGA board. It enables some speed/size code optimizations and allows Mega65 memory mapping to work. + ### `CONFIG_CPU_WDC_65816` Choose if your CPU supports the 16-bit Western Design Center 65816 instruction set, like: @@ -109,10 +121,6 @@ Adds support for the IEEC bus - for serial printers, disk drives, etc. Needs over 1000 bytes in KERNAL segment. If unsure - enable. -### `CONFIG_IEC_BLANK_SCREEN` - -Causes screen blanking during some IEC operations (currently only JiffyDOS file loading) to increase the data transfer performance. - ### `CONFIG_IEC_DOLPHINDOS` Adds support for DolphinDOS fast protocol to the IEC bus, using UserPort cable. @@ -131,6 +139,10 @@ Adds support for JiffyDOS fast protocol to the IEC bus. Needs about 430 bytes in KERNAL segment. If unsure - enable. +### `CONFIG_IEC_JIFFYDOS_BLANK` + +Causes screen blanking during JiffyDOS file loading to increase performance. + ### `CONFIG_TAPE_NORMAL` Adds a minimal normal (standard Commodore format) tape support - just LOAD command. @@ -139,9 +151,17 @@ Needs about 700 bytes in KERNAL segment (if both normal and turbo are enabled, a ### `CONFIG_TAPE_TURBO` -Adds a minimal turbo tape support - just LOAD command (device 7, like on _Action Replay_ and _Final_ cartridges) +Adds a minimal turbo tape support - just LOAD command (device 7, like on _Action Replay_ and _Final_ cartridges), up to 250 blocks -Needs about 650 bytes in KERNAL segment (if both normal and turbo are enabled, about 950 bytes are needed, as they share some code). If unsure - enable. +Needs about 700 bytes in KERNAL segment (if both normal and turbo are enabled, about 950 bytes are needed, as they share some code). If unsure - enable. + +### `CONFIG_TAPE_NO_KEY_SENSE` + +Enable this option if you are using a tape interface adapter with some audio signal source connected. These adapters lack key sense functionality, so the computer is unable to tell whether Play got pressed or not - with this option ROM will assume Play got pressed after imppulses start arriving from the tape. + +### `CONFIG_TAPE_NO_MOTOR_CONTROL` + +Enable this option if you are using a tape interface adapter lacking tape motor control (most likely every adapter currently being sold) - this will eliminate the need to quickly press space when the program header information gets displayed. Note: if you are using a cassette player with REM port, and your adapter is connected to this port too, than you do not need this option. ## Multiple SID support diff --git a/Makefile b/Makefile index 6e5edbf5..c220d998 100644 --- a/Makefile +++ b/Makefile @@ -2,36 +2,38 @@ # Test files TESTDISK = testsuite/testdisk.d64 -TESTTAPE = testsuite/testtape-c64-pal-normal.tap +TESTTAPE = testsuite/testtape-c64-pal-turbo.tap # Source files SRCDIR_COMMON = c64/aliases SRCDIR_BASIC = $(SRCDIR_COMMON) \ - c64/basic \ - c64/basic/commands \ - c64/basic/init \ - c64/basic/rom_revision + c64/basic \ + c64/basic/,stubs \ + c64/basic/commands \ + c64/basic/init \ + c64/basic/rom_revision SRCDIR_KERNAL = $(SRCDIR_COMMON) \ - c64/kernal \ - c64/kernal/,stubs \ - c64/kernal/assets \ - c64/kernal/iec \ - c64/kernal/iec_fast \ - c64/kernal/init \ - c64/kernal/interrupts \ - c64/kernal/iostack \ - c64/kernal/jumptable \ - c64/kernal/keyboard \ - c64/kernal/memory \ - c64/kernal/print \ - c64/kernal/rom_revision \ - c64/kernal/rs232 \ - c64/kernal/screen \ - c64/kernal/tape \ - c64/kernal/time + c64/kernal \ + c64/kernal/,stubs \ + c64/kernal/assets \ + c64/kernal/banking \ + c64/kernal/iec \ + c64/kernal/iec_fast \ + c64/kernal/init \ + c64/kernal/interrupts \ + c64/kernal/iostack \ + c64/kernal/jumptable \ + c64/kernal/keyboard \ + c64/kernal/memory \ + c64/kernal/print \ + c64/kernal/rom_revision \ + c64/kernal/rs232 \ + c64/kernal/screen \ + c64/kernal/tape \ + c64/kernal/time SRC_TOOLS = $(wildcard src/tools/*.c,src/tools/*.cc) @@ -55,12 +57,18 @@ TOOLS_LIST = $(pathsubst src/tools/%,build/tools/%,$(basename $(SRC_TOOLS))) # List of targets -STD_TARGET_LIST = build/kernal_custom.rom build/basic_custom.rom \ - build/kernal_generic.rom build/basic_generic.rom \ - build/kernal_testing.rom build/basic_testing.rom \ - build/kernal_mega65.rom build/basic_mega65.rom \ - build/kernal_ultimate64.rom build/basic_ultimate64.rom \ - build/chargen.rom +STD_TARGET_LIST_CUSTOM = build/kernal_custom.rom build/basic_custom.rom +STD_TARGET_LIST_GENERIC = build/kernal_generic.rom build/basic_generic.rom +STD_TARGET_LIST_TESTING = build/kernal_testing.rom build/basic_testing.rom +STD_TARGET_LIST_ULTIMATE64 = build/kernal_ultimate64.rom build/basic_ultimate64.rom +STD_TARGET_LIST_MEGA65 = build/mega65.rom + +STD_TARGET_LIST = build/chargen.rom \ + $(STD_TARGET_LIST_CUSTOM) \ + $(STD_TARGET_LIST_GENERIC) \ + $(STD_TARGET_LIST_TESTING) \ + $(STD_TARGET_LIST_MEGA65) \ + $(STD_TARGET_LIST_ULTIMATE64) EXT_TARGET_LIST = build/mega65.rom @@ -126,9 +134,9 @@ build/target_testing/OUTB.BIN build/target_testing/BASIC_combined.vs: \ $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC) \ c64/,,config_testing.s build/target_testing/KERNAL_combined.sym \ $(foreach dir,$(SRCDIR_BASIC),$(wildcard $(dir)/*.s)) -build/target_mega65/OUTB.BIN build/target_mega65/BASIC_combined.vs: \ +build/target_mega65/OUTB_0.BIN build/target_mega65/BASIC_0_combined.vs: \ $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC) \ - c64/,,config_mega65.s build/target_mega65/KERNAL_combined.sym \ + c64/,,config_mega65.s build/target_mega65/KERNAL_0_combined.sym \ $(foreach dir,$(SRCDIR_BASIC),$(wildcard $(dir)/*.s)) build/target_ultimate64/OUTB.BIN build/target_ultimate64/BASIC_combined.vs: \ $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC) \ @@ -147,7 +155,7 @@ build/target_testing/OUTK.BIN build/target_testing/KERNAL_combined.vs bu $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_KERNAL) $(SRCDIR_KERNAL) \ c64/,,config_testing.s \ $(foreach dir,$(SRCDIR_KERNAL),$(wildcard $(dir)/*.s)) -build/target_mega65/OUTK.BIN build/target_mega65/KERNAL_combined.vs build/target_mega65/KERNAL_combined.sym: \ +build/target_mega65/OUTK_0.BIN build/target_mega65/KERNAL_0_combined.vs build/target_mega65/KERNAL_0_combined.sym: \ $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_KERNAL) $(SRCDIR_KERNAL) \ c64/,,config_mega65.s \ $(foreach dir,$(SRCDIR_KERNAL),$(wildcard $(dir)/*.s)) @@ -156,28 +164,28 @@ build/target_ultimate64/OUTK.BIN build/target_ultimate64/KERNAL_combined.vs bu c64/,,config_ultimate64.s \ $(foreach dir,$(SRCDIR_KERNAL),$(wildcard $(dir)/*.s)) -build/target_custom/newrom: build/target_custom/OUTB.BIN build/target_custom/OUTK.BIN -build/target_generic/newrom: build/target_generic/OUTB.BIN build/target_generic/OUTK.BIN -build/target_testing/newrom: build/target_testing/OUTB.BIN build/target_testing/OUTK.BIN -build/target_mega65/newrom: build/target_mega65/OUTB.BIN build/target_mega65/OUTK.BIN -build/target_ultimate64/newrom: build/target_ultimate64/OUTB.BIN build/target_ultimate64/OUTK.BIN +build/target_custom/newrom: build/target_custom/OUTB.BIN build/target_custom/OUTK.BIN +build/target_generic/newrom: build/target_generic/OUTB.BIN build/target_generic/OUTK.BIN +build/target_testing/newrom: build/target_testing/OUTB.BIN build/target_testing/OUTK.BIN +build/target_mega65/newrom_0: build/target_mega65/OUTB_0.BIN build/target_mega65/OUTK_0.BIN +build/target_ultimate64/newrom: build/target_ultimate64/OUTB.BIN build/target_ultimate64/OUTK.BIN build/kernal_custom.rom: build/target_custom/newrom build/kernal_generic.rom: build/target_generic/newrom build/kernal_testing.rom: build/target_testing/newrom -build/kernal_mega65.rom: build/target_mega65/newrom +build/kernal_mega65.rom_0: build/target_mega65/newrom_0 build/kernal_ultimate64.rom: build/target_ultimate64/newrom build/basic_custom.rom: build/target_custom/newrom build/basic_generic.rom: build/target_generic/newrom build/basic_testing.rom: build/target_testing/newrom -build/basic_mega65.rom: build/target_mega65/newrom +build/basic_mega65.rom_0: build/target_mega65/newrom_0 build/basic_ultimate64.rom: build/target_ultimate64/newrom build/symbols_custom.vs: build/target_custom/BASIC_combined.vs build/target_custom/KERNAL_combined.vs build/symbols_generic.vs: build/target_generic/BASIC_combined.vs build/target_generic/KERNAL_combined.vs build/symbols_testing.vs: build/target_testing/BASIC_combined.vs build/target_testing/KERNAL_combined.vs -build/symbols_mega65.vs: build/target_mega65/BASIC_combined.vs build/target_mega65/KERNAL_combined.vs +build/symbols_mega65_0.vs: build/target_mega65/BASIC_0_combined.vs build/target_mega65/KERNAL_0_combined.vs build/symbols_ultimate64.vs: build/target_ultimate64/BASIC_combined.vs build/target_ultimate64/KERNAL_combined.vs # Rules - BASIC and KERNAL @@ -190,13 +198,28 @@ build/,generated/packed_messages.s: $(TOOL_COMPRESS_TEXT) build/target_%/OUTB.BIN build/target_%/BASIC_combined.vs: @mkdir -p build/target_$* @rm -f $@* build/target_$*/BASIC* - @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -s BASIC -i BASIC-$* -o OUTB.BIN -d build/target_$* -l a000 -h e4d2 c64/,,config_$*.s $(SRCDIR_BASIC) $(GEN_BASIC) + @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -r STD -s BASIC -i BASIC-$* -o OUTB.BIN -d build/target_$* -l a000 -h e4d2 c64/,,config_$*.s $(SRCDIR_BASIC) $(GEN_BASIC) .PRECIOUS: build/target_%/OUTK.BIN build/target_%/KERNAL_combined.vs build/target_%/KERNAL_combined.sym build/target_%/OUTK.BIN build/target_%/KERNAL_combined.vs build/target_%/KERNAL_combined.sym: @mkdir -p build/target_$* @rm -f $@* build/target_$*/KERNAL* - @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -s KERNAL -i KERNAL-$* -o OUTK.BIN -d build/target_$* -l e4d3 -h ffff c64/,,config_$*.s $(SRCDIR_KERNAL) $(GEN_KERNAL) + @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -r STD -s KERNAL -i KERNAL-$* -o OUTK.BIN -d build/target_$* -l e4d3 -h ffff c64/,,config_$*.s $(SRCDIR_KERNAL) $(GEN_KERNAL) + +build/target_mega65/OUTB_0.BIN build/target_mega65/BASIC_0_combined.vs: + @mkdir -p build/target_mega65 + @rm -f $@* build/target_mega65/BASIC_0* + @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -r M65 -s BASIC_0 -i BASIC_0-mega65 -o OUTB_0.BIN -d build/target_mega65 -l a000 -h e4d2 c64/,,config_mega65.s $(SRCDIR_BASIC) $(GEN_BASIC) + +build/target_mega65/OUTK_0.BIN build/target_mega65/KERNAL_0_combined.vs build/target_mega65/KERNAL_0_combined.sym: + @mkdir -p build/target_mega65 + @rm -f $@* build/target_mega65/KERNAL_0* + @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -r M65 -s KERNAL_0 -i KERNAL_0-mega65 -o OUTK_0.BIN -d build/target_mega65 -l e4d3 -h ffff c64/,,config_mega65.s $(SRCDIR_KERNAL) $(GEN_KERNAL) + +build/target_mega65/kernal.seg_1 build/target_mega65/KERNAL_1_combined.vs build/target_mega65/KERNAL_1_combined.sym: $(TOOL_BUILD_SEGMENT) + @mkdir -p build/target_mega65 + @rm -f $@* build/target_mega65/kernal.seg_1 build/target_mega65/KERNAL_1* + @$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -r M65 -s KERNAL_1 -i KERNAL_1-mega65 -o kernal.seg_1 -d build/target_mega65 -l 4000 -h 5fff c64/,,config_mega65.s $(SRCDIR_KERNAL) $(GEN_KERNAL) .PRECIOUS: build/target_%/newrom build/target_%/newrom: @@ -214,6 +237,15 @@ build/basic_%.rom: build/symbols_%.vs: sort build/target_$*/BASIC_combined.vs build/target_$*/KERNAL_combined.vs | uniq | grep -v "__" > $@ +build/target_mega65/newrom_0: + cat build/target_mega65/OUTB_0.BIN build/target_mega65/OUTK_0.BIN > $@ + +build/kernal_mega65.rom_0: + dd if=build/target_mega65/newrom_0 bs=8192 count=1 skip=2 of=$@ + +build/basic_mega65.rom_0: + dd if=build/target_mega65/newrom_0 bs=8192 count=1 skip=0 of=$@ + build/kernal_hybrid.rom: kernal build/target_generic/OUTK.BIN @echo @echo $(HYBRID_WARNING) @@ -228,12 +260,19 @@ build/symbols_hybrid.vs: build/target_generic/KERNAL_combined.vs # Rules - platform 'Mega 65' specific -build/mega65.rom: build/kernal_mega65.rom build/basic_mega65.rom build/chargen.rom - dd if=/dev/zero bs=4096 count=10 of=build/mega65.rom - cat build/basic_mega65.rom build/chargen.rom build/chargen.rom build/kernal_mega65.rom >> build/mega65.rom - dd if=/dev/zero bs=65536 count=1 of=build/padding - cat build/padding >> build/mega65.rom - rm -f build/padding +build/mega65.rom: build/kernal_mega65.rom_0 build/target_mega65/kernal.seg_1 build/basic_mega65.rom_0 build/chargen.rom + dd if=/dev/zero bs=8192 count=1 of=build/padding_8k + dd if=/dev/zero bs=8192 count=8 of=build/padding_64k + cat build/padding_8k > build/mega65.rom + cat build/padding_8k >> build/mega65.rom + cat build/target_mega65/kernal.seg_1 >> build/mega65.rom + cat build/padding_8k >> build/mega65.rom + cat build/padding_8k >> build/mega65.rom + cat build/basic_mega65.rom_0 >> build/mega65.rom + cat build/chargen.rom build/chargen.rom >> build/mega65.rom + cat build/kernal_mega65.rom_0 >> build/mega65.rom + cat build/padding_64k >> build/mega65.rom + rm -f build/padding* # Rules - tests @@ -256,9 +295,6 @@ test_generic_x128: build/kernal_generic.rom build/basic_generic.rom build/symbol test_testing: build/kernal_testing.rom build/basic_testing.rom build/symbols_testing.vs x64 -kernal build/kernal_testing.rom -basic build/basic_testing.rom -moncommands build/symbols_testing.vs -1 $(TESTTAPE) -8 $(TESTDISK) -test_mega65_vice: build/kernal_mega65.rom build/basic_mega65.rom build/symbols_mega65.vs - x64 -kernal build/kernal_mega65.rom -basic build/basic_mega65.rom -moncommands build/symbols_mega65.vs -1 $(TESTTAPE) -8 $(TESTDISK) - test_mega65: build/mega65.rom ../xemu/build/bin/xmega65.native -dmarev 2 -forcerom -loadrom build/mega65.rom diff --git a/README.md b/README.md index fd201623..9a966ccb 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ A project to create unencumbered open-source ROMs for use on selected retro computers. Besides this manifest, the following documents are available: -* [implementation status](STATUS.md) of various APIs and functionalities -* [configuration options](CONFIG.md) for those willing to compile their own, customized build +* [implementation status](./STATUS.md) of various APIs and functionalities +* [configuration options](./CONFIG.md) for those willing to compile their own, customized ROM set +* [development guide](./doc/Development.md) for those interested in OpenROMs technical aspects # Problem Statement and Motivation diff --git a/STATUS.md b/STATUS.md index 865001d7..80eed824 100644 --- a/STATUS.md +++ b/STATUS.md @@ -4,15 +4,15 @@ Here are the features of the Open ROMs not found in the original ROMs from the 80s (many of them are [configurable](CONFIG.md) during compilation): -* improved keyboard scanning, resistant to ghosting and joystick interference (one variant even supports multi-keyy rollover), supports additional C128 keys +* improved keyboard scanning, resistant to ghosting and joystick interference (one variant even supports multi-key rollover), supports additional C128 keys * joystick can be used to move text cursor * pre-defined function keys -* JiffyDOS protocol support -* partial DolphinDOS protocol support +* JiffyDOS and DolphinDOS protocols support * DOS wedge (direct mode only) - `@`, `@`, `@$`, `@$`, `@` -* turbo tape load support (as device 7, or using `←L`), up to 250 blocks (can store bytes under I/O) +* turbo tape load support (as device 7, or using `←L`), quite sophisticated: up to 250 blocks (can store bytes under I/O), automatically adjusts for tape speed differences +* improved support for tape adapters (for using regular casette players and other audio devices instead of Datasette) * extended `LOAD` command * start/end addresses are displayed, in the Final cartridge style @@ -48,28 +48,29 @@ The following ROM features are currently missing: ## Keyboard -| Driver | Status | Remarks | -| :-----------: | :------: | :------------------------------------------------: | -| C64 | DONE | | -| C128 | DONE | | -| Mega65 | NOT DONE | code should be complete, but is not tested yet | +| Driver | Status | Remarks | +| :----------------: | :------: | :------------------------------------------------: | +| C64 | DONE | | +| C128 | DONE | | +| Mega65 | NOT DONE | code should be complete, but is not tested yet | ## Screen -| Driver | Status | Remarks | -| :-----------: | :------: | :------------------------------------------------: | -| VIC-II | PARTIAL | 80 chars in logical line support is very buggy | -| VDC 80 col. | NOT DONE | | +| Driver | Status | Remarks | +| :----------------: | :------: | :------------------------------------------------: | +| VIC-II | DONE | | +| 80 columns, VDC | NOT DONE | | +| 80 columns, Mega65 | NOT DONE | | ## Tape port (LOAD only!) * Tapuino * Datasette -| Driver | Status | Remarks | -| :-----------: | :------: | :------------------------------------------------: | -| normal | PARTIAL | no error correction, no tape speed calibratrion | -| turbo | PARTIAL | up to 250 blocks, no tape speed calibratrion yet | +| Driver | Status | Remarks | +| :----------------: | :------: | :------------------------------------------------: | +| normal | PARTIAL | no tape speed calibratrion, no error correction | +| turbo (250 blocks) | DONE | | ## IEC bus @@ -78,13 +79,13 @@ The following ROM features are currently missing: * most disk drives and printers * some hard drives -| Driver | Status | Remarks | -| :-----------: | :------: | :------------------------------------------------: | -| standard | DONE | | -| JiffyDOS | DONE | | -| DolphinDOS | DONE | | -| CIA burst mod | NOT DONE | | -| Mega65 burst | NOT DONE | pure software implementation should be feasible | +| Driver | Status | Remarks | +| :----------------: | :------: | :------------------------------------------------: | +| standard | DONE | | +| JiffyDOS | DONE | | +| DolphinDOS | DONE | | +| CIA burst mod | NOT DONE | | +| Mega65 burst | NOT DONE | | ## IEEE-488 bus @@ -92,20 +93,20 @@ The following ROM features are currently missing: * PET era disk drives and printers * various scientific equipment -| Driver | Status | Remarks | -| :-----------: | :------: | :------------------------------------------------: | -| CBM cartridge | NOT DONE | | +| Driver | Status | Remarks | +| :----------------: | :------: | :------------------------------------------------: | +| CBM cartridge | NOT DONE | | ## RS-232 * modems (telephone, WiFi) * parallel port printers -| Driver | Status | Remarks | -| :-----------: | :------: | :------------------------------------------------: | -| UP2400 | NOT DONE | | -| UP9600 | NOT DONE | work started, not functional yet | -| ACIA 6551 | NOT DONE | | +| Driver | Status | Remarks | +| :----------------: | :------: | :------------------------------------------------: | +| UP2400 | NOT DONE | | +| UP9600 | NOT DONE | work started, not functional yet | +| ACIA 6551 | NOT DONE | | # API status @@ -178,7 +179,7 @@ NOTE: Even the 'DONE' routines won't support features described as missing in on | :-------: | :--------: | :---------- | :------: | :--------------------------------------------------: | | `($028F)` | | `KEYLOG` | DONE | | | `$FF81` | `$FF5B` | `CINT` | DONE | | -| `$FF84` | `$FDA3` | `IOINIT` | PARTIAL | CIA initialization incomplete | +| `$FF84` | `$FDA3` | `IOINIT` | DONE | | | `$FF87` | `$FD50` | `RAMTAS` | DONE | | | `$FF8A` | `$FD15` | `RESTOR` | DONE | | | `$FF8D` | `$FD1A` | `VECTOR` | DONE | | @@ -219,7 +220,7 @@ NOTE: Even the 'DONE' routines won't support features described as missing in on | `$FFF0` | `$E50A` | `PLOT` | DONE | | | `$FFF3` | | `IOBASE` | DONE | | | `($FFFA)` | | NMI vec | PARTIAL | | -| `($FFFC)` | `$FCE2` | RESET vec | PARTIAL | see IOINIT status | +| `($FFFC)` | `$FCE2` | RESET vec | DONE | | | `($FFFE)` | | IRQ/BRK vec | DONE | |
@@ -235,20 +236,22 @@ Not all of them - only these we want to have implemented. | `$E518` | legacy part of CINT | DONE | | | `$E51B` | init screen keyboard, no VIC | DONE | | | `$E544` | clear screen | DONE | | -| `$E50C` | set cursor position | PARTIAL | | -| `$E566` | home cursor | NOT DONE | | +| `$E50C` | set cursor position | DONE | | +| `$E566` | home cursor | DONE | | +| `$E56C` | set PNT and USER values | DONE | | | `$E5A0` | setup VIC II & I/O | DONE | | | `$E6B6` | advance cursor | NOT DONE | | | `$E701` | previous line | NOT DONE | | | `$E716` | screen CHROUT | NOT DONE | | | `$E8DA` | color code table | DONE | | -| `$E8EA` | scroll line | NOT DONE | | +| `$E8EA` | scroll logical line up | DONE | | | `$E96C` | insert line on top | NOT DONE | | -| `$E9FF` | clear line | NOT DONE | | +| `$E9FF` | clear line | DONE | | | `$EA31` | default IRQ | PARTIAL | | | `$EA7E` | ack CIA1 + below | DONE | | | `$EA81` | ret from IRQ/NMI | DONE | | | `$F142` | get key from buffer | DONE | | +| `$F3F6` | (unknown) | NOT DONE | | | `$F646` | IEC close | NOT DONE | | | `$FD30` | default vectors | DONE | | | `$FD90` | (unknown) | NOT DONE | | diff --git a/bin/basic_generic.rom b/bin/basic_generic.rom index 5adcd38c..e3d073ac 100644 Binary files a/bin/basic_generic.rom and b/bin/basic_generic.rom differ diff --git a/bin/basic_testing.rom b/bin/basic_testing.rom index d39223eb..fb950a74 100644 Binary files a/bin/basic_testing.rom and b/bin/basic_testing.rom differ diff --git a/bin/basic_ultimate64.rom b/bin/basic_ultimate64.rom index d03026e6..6bbbab86 100644 Binary files a/bin/basic_ultimate64.rom and b/bin/basic_ultimate64.rom differ diff --git a/bin/kernal_generic.rom b/bin/kernal_generic.rom index 5cf03a31..90a888be 100644 Binary files a/bin/kernal_generic.rom and b/bin/kernal_generic.rom differ diff --git a/bin/kernal_testing.rom b/bin/kernal_testing.rom index 4db16e98..74a71589 100644 Binary files a/bin/kernal_testing.rom and b/bin/kernal_testing.rom differ diff --git a/bin/kernal_ultimate64.rom b/bin/kernal_ultimate64.rom index cd8e33aa..754f75c7 100644 Binary files a/bin/kernal_ultimate64.rom and b/bin/kernal_ultimate64.rom differ diff --git a/bin/mega65.rom b/bin/mega65.rom index 63418690..6f99bd91 100644 Binary files a/bin/mega65.rom and b/bin/mega65.rom differ diff --git a/c64/,,config_custom.s b/c64/,,config_custom.s index 2e6799c1..60fa3d47 100644 --- a/c64/,,config_custom.s +++ b/c64/,,config_custom.s @@ -33,6 +33,7 @@ #define CONFIG_CPU_MOS_6502 // #define CONFIG_CPU_WDC_65C02 // #define CONFIG_CPU_CSG_65CE02 +// #define CONFIG_CPU_M65_45GS02 // #define CONFIG_CPU_WDC_65816 @@ -45,16 +46,22 @@ // I/O devices #define CONFIG_IEC -#define CONFIG_IEC_BLANK_SCREEN -#define CONFIG_IEC_DOLPHINDOS // not finished yet, but LOAD works +#define CONFIG_IEC_DOLPHINDOS #define CONFIG_IEC_DOLPHINDOS_FAST #define CONFIG_IEC_JIFFYDOS +#define CONFIG_IEC_JIFFYDOS_BLANK +// #define CONFIG_IEC_BURST_CIA1 // please keep disabled for now +// #define CONFIG_IEC_BURST_CIA2 // please keep disabled for now +// #define CONFIG_IEC_BURST_SOFT // please keep disabled for now #define CONFIG_TAPE_NORMAL #define CONFIG_TAPE_TURBO +#define CONFIG_TAPE_AUTODETECT // mostly works, but not fullyy done yet! +// #define CONFIG_TAPE_NO_KEY_SENSE +// #define CONFIG_TAPE_NO_MOTOR_CONTROL -// #define CONFIG_RS232_UP2400 // please keep disabled for now -// #define CONFIG_RS232_UP9600 // please keep disabled for now +// #define CONFIG_RS232_UP2400 // please keep disabled for now +// #define CONFIG_RS232_UP9600 // please keep disabled for now // Multiple SID support diff --git a/c64/,,config_generic.s b/c64/,,config_generic.s index 258caf5a..4195ef46 100644 --- a/c64/,,config_generic.s +++ b/c64/,,config_generic.s @@ -30,6 +30,7 @@ #define CONFIG_CPU_MOS_6502 // #define CONFIG_CPU_WDC_65C02 // #define CONFIG_CPU_CSG_65CE02 +// #define CONFIG_CPU_M65_45GS02 // #define CONFIG_CPU_WDC_65816 @@ -42,13 +43,15 @@ // I/O devices #define CONFIG_IEC -#define CONFIG_IEC_BLANK_SCREEN #define CONFIG_IEC_DOLPHINDOS #define CONFIG_IEC_DOLPHINDOS_FAST #define CONFIG_IEC_JIFFYDOS +#define CONFIG_IEC_JIFFYDOS_BLANK #define CONFIG_TAPE_NORMAL #define CONFIG_TAPE_TURBO +// #define CONFIG_TAPE_NO_KEY_SENSE +// #define CONFIG_TAPE_NO_MOTOR_CONTROL // Multiple SID support diff --git a/c64/,,config_mega65.s b/c64/,,config_mega65.s index eebb62e4..add9c08e 100644 --- a/c64/,,config_mega65.s +++ b/c64/,,config_mega65.s @@ -29,7 +29,8 @@ // #define CONFIG_CPU_MOS_6502 // #define CONFIG_CPU_WDC_65C02 -#define CONFIG_CPU_CSG_65CE02 +// #define CONFIG_CPU_CSG_65CE02 +#define CONFIG_CPU_M65_45GS02 // #define CONFIG_CPU_WDC_65816 @@ -42,13 +43,15 @@ // I/O devices #define CONFIG_IEC -#define CONFIG_IEC_BLANK_SCREEN // #define CONFIG_IEC_DOLPHINDOS // #define CONFIG_IEC_DOLPHINDOS_FAST #define CONFIG_IEC_JIFFYDOS +#define CONFIG_IEC_JIFFYDOS_BLANK // #define CONFIG_TAPE_NORMAL // #define CONFIG_TAPE_TURBO +// #define CONFIG_TAPE_NO_KEY_SENSE +// #define CONFIG_TAPE_NO_MOTOR_CONTROL // Multiple SID support @@ -119,7 +122,7 @@ // #define CONFIG_BANNER_SIMPLE // #define CONFIG_BANNER_FANCY #define CONFIG_BANNER_BRAND -#define CONFIG_SHOW_FEATURES +// #define CONFIG_SHOW_FEATURES // #define CONFIG_SHOW_PAL_NTSC diff --git a/c64/,,config_testing.s b/c64/,,config_testing.s index 317eeed9..0f7a164f 100644 --- a/c64/,,config_testing.s +++ b/c64/,,config_testing.s @@ -30,6 +30,7 @@ #define CONFIG_CPU_MOS_6502 // #define CONFIG_CPU_WDC_65C02 // #define CONFIG_CPU_CSG_65CE02 +// #define CONFIG_CPU_M65_45GS02 // #define CONFIG_CPU_WDC_65816 @@ -42,13 +43,15 @@ // I/O devices #define CONFIG_IEC -// #define CONFIG_IEC_BLANK_SCREEN #define CONFIG_IEC_DOLPHINDOS // #define CONFIG_IEC_DOLPHINDOS_FAST #define CONFIG_IEC_JIFFYDOS +// #define CONFIG_IEC_JIFFYDOS_BLANK // #define CONFIG_TAPE_NORMAL #define CONFIG_TAPE_TURBO +// #define CONFIG_TAPE_NO_KEY_SENSE +// #define CONFIG_TAPE_NO_MOTOR_CONTROL // Multiple SID support diff --git a/c64/,,config_ultimate64.s b/c64/,,config_ultimate64.s index 3d4cce51..f2927c60 100644 --- a/c64/,,config_ultimate64.s +++ b/c64/,,config_ultimate64.s @@ -30,6 +30,7 @@ #define CONFIG_CPU_MOS_6502 // #define CONFIG_CPU_WDC_65C02 // #define CONFIG_CPU_CSG_65CE02 +// #define CONFIG_CPU_M65_45GS02 // #define CONFIG_CPU_WDC_65816 @@ -42,13 +43,15 @@ // I/O devices #define CONFIG_IEC -#define CONFIG_IEC_BLANK_SCREEN #define CONFIG_IEC_DOLPHINDOS #define CONFIG_IEC_DOLPHINDOS_FAST #define CONFIG_IEC_JIFFYDOS +#define CONFIG_IEC_JIFFYDOS_BLANK #define CONFIG_TAPE_NORMAL #define CONFIG_TAPE_TURBO +// #define CONFIG_TAPE_NO_KEY_SENSE +// #define CONFIG_TAPE_NO_MOTOR_CONTROL // Multiple SID support diff --git a/c64/aliases/,aliases_config.s b/c64/aliases/,aliases_config.s index c9a096d9..60bbddc6 100644 --- a/c64/aliases/,aliases_config.s +++ b/c64/aliases/,aliases_config.s @@ -88,6 +88,9 @@ #if CONFIG_CPU_CSG_65CE02 .eval selected++ #endif +#if CONFIG_CPU_M65_45GS02 + .eval selected++ +#endif #if CONFIG_CPU_WDC_65816 .eval selected++ #endif @@ -97,8 +100,15 @@ -// Check that memory model configuration is correct +// Check that memory model and ROM layout configurations is correct { +#if ROM_LAYOUT_M65 && !CONFIG_CPU_M65_45GS02 + .error "Mega65 ROM layout requires CONFIG_CPU_M65_45GS02" +#endif +//#if ROM_LAYOUT_M65 && !CONFIG_MB_MEGA_65 +// .error "Mega65 ROM layout requires CONFIG_MB_MEGA_65" +//#endif + .var selected = 0; #if CONFIG_MEMORY_MODEL_38K @@ -112,10 +122,15 @@ } -// Check that I/O configuration is correct + +// Check that IEC configuration is correct { -#if CONFIG_RS232_UP9600 && (CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO) - .error "CONFIG_RS232_UP9600 is not compatible with CONFIG_TAPE_*" +#if CONFIG_IEC_JIFFYDOS && !CONFIG_IEC + .error "CONFIG_IEC_JIFFYDOS requires CONFIG_IEC" +#endif + +#if CONFIG_IEC_JIFFYDOS_BLANK && !CONFIG_IEC_JIFFYDOS + .error "CONFIG_IEC_JIFFYDOS_BLANK requires CONFIG_IEC_JIFFYDOS" #endif #if CONFIG_IEC_DOLPHINDOS && !CONFIG_IEC @@ -126,8 +141,44 @@ .error "CONFIG_IEC_DOLPHINDOS_FAST requires CONFIG_IEC_DOLPHINDOS" #endif -#if CONFIG_IEC_JIFFYDOS && !CONFIG_IEC - .error "CONFIG_IEC_JIFFYDOS requires CONFIG_IEC" +#if (CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_SOFT) && !CONFIG_IEC + .error "CONFIG_IEC_BURST_* requires CONFIG_IEC" +#endif + +#if CONFIG_IEC_BURST_SOFT && !CONFIG_MB_MEGA_65 + .error "CONFIG_IEC_BURST_SOFT requires CONFIG_MB_MEGA_65" +#endif + + .var selected_iec_burst = 0; + +#if CONFIG_IEC_BURST_CIA1 + .eval selected_iec_burst++ +#endif +#if CONFIG_IEC_BURST_CIA2 + .eval selected_iec_burst++ +#endif +#if CONFIG_IEC_BURST_SOFT + .eval selected_iec_burst++ +#endif + + .if (selected_iec_burst > 1) .error "Please select at most one CONFIG_IEC_BURST_* option" +} + + + +// Check that tape configuration is correct +{ +#if (!CONFIG_TAPE_NORMAL || !CONFIG_TAPE_TURBO) && CONFIG_TAPE_AUTODETECT + .error "CONFIG_TAPE_AUTODETECT requires both CONFIG_TAPE_NORMAL and CONFIG_TAPE_TURBO" +#endif +} + + + +// Check that RS-232 configuration is correct +{ +#if CONFIG_RS232_UP9600 && (CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO) + .error "CONFIG_RS232_UP9600 is not compatible with CONFIG_TAPE_*" #endif .var selected_rs232 = 0; @@ -143,6 +194,7 @@ } + // Check that startup banner configuration is correct { .var selected = 0; @@ -322,13 +374,22 @@ #if CONFIG_IEC .var iec_features_str = "IEC" +#if CONFIG_IEC_BURST_CIA1 + .eval iec_features_str = iec_features_str + " BURST1" +#endif +#if CONFIG_IEC_BURST_CIA2 + .eval iec_features_str = iec_features_str + " BURST2" +#endif +#if CONFIG_IEC_BURST_SOFT + .eval iec_features_str = iec_features_str + " BURST" +#endif #if CONFIG_IEC_DOLPHINDOS .eval iec_features_str = iec_features_str + " DOLPHIN" #endif #if CONFIG_IEC_JIFFYDOS .eval iec_features_str = iec_features_str + " JIFFY" #endif -#if !CONFIG_IEC_DOLPHINDOS && !CONFIG_IEC_JIFFYDOS +#if !CONFIG_IEC_BURST_CIA1 && !CONFIG_IEC_BURST_CIA2 && !CONFIG_IEC_BURST_SOFT && !CONFIG_IEC_DOLPHINDOS && !CONFIG_IEC_JIFFYDOS .eval iec_features_str = iec_features_str + " NORMAL" #endif .eval features_str = ADD_FEATURE(features_str, iec_features_str) diff --git a/c64/aliases/,aliases_cpu.s b/c64/aliases/,aliases_cpu.s index 023e7558..cf99d957 100644 --- a/c64/aliases/,aliases_cpu.s +++ b/c64/aliases/,aliases_cpu.s @@ -1,26 +1,31 @@ + // // Provide pseudocommands (and other goodies) to make CPU optimizations easier // - -#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_CSG_65CE02 || CONFIG_CPU_WDC_65816 +#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_CSG_65CE02 || CONFIG_CPU_CSG_4510 || CONFIG_CPU_M65_45GS02 || CONFIG_CPU_WDC_65816 .cpu _65c02 #define HAS_OPCODES_65C02 + #define HAS_BCD_SAFE_INTERRUPTS #endif -#if CONFIG_CPU_CSG_65CE02 +#if CONFIG_CPU_CSG_65CE02 || CONFIG_CPU_CSG_4510 || CONFIG_CPU_M65_45GS02 #define HAS_OPCODES_65CE02 #endif +#if CONFIG_CPU_CSG_4510 || CONFIG_CPU_M65_45GS02 + #define HAS_OPCODES_4510 +#endif + +#if CONFIG_CPU_M65_45GS02 + #define HAS_OPCODES_45GS02 +#endif + #if CONFIG_CPU_WDC_65816 #define HAS_OPCODES_65816 #endif -#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_CSG_65CE02 || CONFIG_CPU_WDC_65816 - #define HAS_BCD_SAFE_INTERRUPTS -#endif - // // These are not exactly for optimization - but to encourage proper usage of panic screen @@ -36,24 +41,50 @@ } + // // Trick to skip a 2-byte instruction // +.pseudocommand skip_2_bytes_trash_nvz { .byte $2C } + + + +// +// Memory mapping for C65 and Mega65 +// + +#if HAS_OPCODES_4510 + +.pseudocommand map { .byte $5C } +.pseudocommand eom { .byte $EA } + +#endif -.pseudocommand skip_2_bytes_trash_nvz -{ - .byte $2C -} // // Some additional 65CE02 instructions // - #if HAS_OPCODES_65CE02 +// .B register support + +.pseudocommand tab { .byte $5B } +.pseudocommand tba { .byte $7B } + +// .Z register support + +.pseudocommand inz { .byte $1B } +.pseudocommand dez { .byte $3B } +.pseudocommand phz { .byte $DB } +.pseudocommand plz { .byte $FB } +.pseudocommand taz { .byte $4B } +.pseudocommand tza { .byte $6B } + +// 16-bit data processing + .pseudocommand dew addr { .var arg = addr.getValue() @@ -71,11 +102,11 @@ #endif + // // Stack manipulation - some CPUs will leave .A unchanged, some will use it as temporary storage, so consider .A trashed // - .pseudocommand phx_trash_a { #if HAS_OPCODES_65C02 @@ -117,15 +148,15 @@ } + // // Branches with far offsets, substitutes by Bxx + JMP for CPUs not supporting the instruction // - -.pseudocommand bcs_far dst +.pseudocommand bcs_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $B3, mod(offset, $100), floor(offset / $100) #else bcc __l @@ -134,10 +165,10 @@ __l: #endif } -.pseudocommand bcc_far dst +.pseudocommand bcc_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $93, mod(offset, $100), floor(offset / $100) #else bcs __l @@ -146,10 +177,10 @@ __l: #endif } -.pseudocommand beq_far dst +.pseudocommand beq_16 dst { -#if HAS_OPCODES_65CE02 && XXX_DISABLED // XXX causes problems with XEMU, investigate why - .var offset = mod($10000 + dst.getValue() - *, $10000) +#if HAS_OPCODES_65CE02 + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $F3, mod(offset, $100), floor(offset / $100) #else bne __l @@ -158,10 +189,10 @@ __l: #endif } -.pseudocommand bne_far dst +.pseudocommand bne_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $D3, mod(offset, $100), floor(offset / $100) #else beq __l @@ -170,10 +201,10 @@ __l: #endif } -.pseudocommand bmi_far dst +.pseudocommand bmi_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $33, mod(offset, $100), floor(offset / $100) #else bpl __l @@ -182,10 +213,10 @@ __l: #endif } -.pseudocommand bpl_far dst +.pseudocommand bpl_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $13, mod(offset, $100), floor(offset / $100) #else bmi __l @@ -194,10 +225,10 @@ __l: #endif } -.pseudocommand bvc_far dst +.pseudocommand bvc_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $53, mod(offset, $100), floor(offset / $100) #else bvs __l @@ -206,10 +237,10 @@ __l: #endif } -.pseudocommand bvs_far dst +.pseudocommand bvs_16 dst { #if HAS_OPCODES_65CE02 - .var offset = mod($10000 + dst.getValue() - *, $10000) + .var offset = mod($10000 + dst.getValue() - *, $10000) -2 .byte $73, mod(offset, $100), floor(offset / $100) #else bvc __l diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s index c554e0de..4e6d2593 100644 --- a/c64/aliases/,aliases_ram_lowmem.s +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -88,7 +88,7 @@ .label VERCKK = $93 // 0 = LOAD, 1 = VERIFY .label C3PO = $94 // flag - is BSOUR content valid .label BSOUR = $95 // serial bus buffered output byte - .label SYNO = $96 // -- NOT IMPLEMENTED -- + .label SYNO = $96 // temporary tape routines storage, [!] our usage differs .label XSAV = $97 // temporary register storage for ASCII/tape related routines [!] usage details might differ .label LDTND = $98 // number of entries in LAT / FAT / SAT tables .label DFLTN = $99 // default input device @@ -103,7 +103,7 @@ .label PTR1 = $9E // -- NOT IMPLEMENTED -- .label PTR2 = $9F // -- NOT IMPLEMENTED -- .label TIME = $A0 // $A0-$A2 jiffy clock -#if !CONFIG_IEC_JIFFYDOS && !CONFIG_IEC_DOLPHINDOS +#if !CONFIG_IEC_JIFFYDOS && !CONFIG_IEC_DOLPHINDOS && !CONFIG_IEC_BURST_CIA1 && !CONFIG_IEC_BURST_CIA2 && !CONFIG_IEC_BURST_SOFT .label TSFCNT = $A3 // temporary variable for tape and IEC, [!] our usage differs #else .label IECPROTO = $A3 // -- WIP -- [!] 0 = normal, 1 = JiffyDOS, >= $80 for unknown @@ -153,10 +153,10 @@ .label BLNON = $CF // cursor visibility flag .label CRSW = $D0 // whether to input from screen or keyboard .label PNT = $D1 // $D1-$D2 pointer to the current screen line - .label PNTR = $D3 // current screen X position + .label PNTR = $D3 // current screen X position (logical column), 0-79 .label QTSW = $D4 // quote mode flag - .label LNMX = $D5 // logical line length, [!] our usage probably differs in details - .label TBLX = $D6 // current screen Y position + .label LNMX = $D5 // logical line length, 39 or 79 + .label TBLX = $D6 // current screen Y position (row), 0-24 .label SCHAR = $D7 // ASCII value of the last printed character .label INSRT = $D8 // insert mode flag/counter .label LDTBL = $D9 // $D9-$F2 screen line link table, [!] our usage is different XXX give more details @@ -214,7 +214,7 @@ .label RIDBS = $29C // -- WIP -- read pointer into RS-232 receive buffer .label RODBS = $29D // -- WIP -- read pointer into RS-232 send buffer .label RODBE = $29E // -- WIP -- write pointer into RS-232 send buffer - .label IRQTMP = $29F // $29F-$2A0 -- NOT IMPLEMENTED -- + .label IRQTMP = $29F // $29F-$2A0 temporary IRQ vector storage [!] we use it for tape speed calibration instead .label ENABL = $2A1 // -- NOT IMPLEMENTED -- .label TODSNS = $2A2 // -- NOT IMPLEMENTED -- .label TRDTMP = $2A3 // -- NOT IMPLEMENTED -- diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index 2726f748..37741819 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -1,3 +1,4 @@ + // // Helper aliases to make the code more readable // Always use double underscore in label names diff --git a/c64/basic/,imports.s b/c64/basic/,imports.s index 525459f4..ebcf56c9 100644 --- a/c64/basic/,imports.s +++ b/c64/basic/,imports.s @@ -1,28 +1,42 @@ // Routines imported from Kernal - our private API -#import "KERNAL_combined.sym" +#if ROM_LAYOUT_STD + #import "KERNAL_combined.sym" +#else + #import "KERNAL_0_combined.sym" +#endif + + +.function KERNAL() +{ +#if ROM_LAYOUT_STD + .return KERNAL +#else + .return KERNAL_0 +#endif +} #if CONFIG_PANIC_SCREEN -.label panic = KERNAL.panic +.label panic = KERNAL().panic #endif -.label hw_entry_reset = KERNAL.hw_entry_reset +.label hw_entry_reset = KERNAL().hw_entry_reset #if CONFIG_DBG_PRINTF -.label printf = KERNAL.printf +.label printf = KERNAL().printf #endif -.label plot_set = KERNAL.plot_set -.label print_hex_byte = KERNAL.print_hex_byte -.label print_return = KERNAL.print_return -.label print_space = KERNAL.print_space +.label plot_set = KERNAL().plot_set +.label print_hex_byte = KERNAL().print_hex_byte +.label print_return = KERNAL().print_return +.label print_space = KERNAL().print_space #if CONFIG_SHOW_FEATURES -.label print_features = KERNAL.print_features +.label print_features = KERNAL().print_features #endif #if CONFIG_SHOW_PAL_NTSC -.label print_pal_ntsc = KERNAL.print_pal_ntsc +.label print_pal_ntsc = KERNAL().print_pal_ntsc #endif diff --git a/c64/basic/a408.interop b/c64/basic/,stubs/a408.interop similarity index 100% rename from c64/basic/a408.interop rename to c64/basic/,stubs/a408.interop diff --git a/c64/basic/,stubs/a408.reason.s b/c64/basic/,stubs/a408.reason.s new file mode 100644 index 00000000..8bca5016 --- /dev/null +++ b/c64/basic/,stubs/a408.reason.s @@ -0,0 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and implementation + +REASON: + STUB_IMPLEMENTATION() diff --git a/c64/basic/a453.interop b/c64/basic/,stubs/a453.interop similarity index 100% rename from c64/basic/a453.interop rename to c64/basic/,stubs/a453.interop diff --git a/c64/basic/,stubs/a453.unknown.s b/c64/basic/,stubs/a453.unknown.s new file mode 100644 index 00000000..02ae9dac --- /dev/null +++ b/c64/basic/,stubs/a453.unknown.s @@ -0,0 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and implementation + + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs/a483.main.s b/c64/basic/,stubs/a483.main.s new file mode 100644 index 00000000..f15fd4d2 --- /dev/null +++ b/c64/basic/,stubs/a483.main.s @@ -0,0 +1,17 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_BASIC_0) + +// +// Official BASIC routine, described in: +// +// - [RG64] C64 Programmers Reference Guide - XXX +// - [CM64] Computes Mapping the Commodore 64 - page 69, XXX +// +// CPU registers that has to be preserved (see [RG64]): XXX +// + + +MAIN: + STUB_IMPLEMENTATION() + + +#endif // ROM layout diff --git a/c64/basic/,stubs/a57c.chrnch.s b/c64/basic/,stubs/a57c.chrnch.s new file mode 100644 index 00000000..b5e3df12 --- /dev/null +++ b/c64/basic/,stubs/a57c.chrnch.s @@ -0,0 +1,16 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Official BASIC routine, described in: +// +// - [RG64] C64 Programmers Reference Guide - XXX +// - [CM64] Computes Mapping the Commodore 64 - page 69, XXX +// +// CPU registers that has to be preserved (see [RG64]): XXX +// + + +CHRNCH: + STUB_IMPLEMENTATION() diff --git a/c64/basic/a57c.interop b/c64/basic/,stubs/a57c.interop similarity index 100% rename from c64/basic/a57c.interop rename to c64/basic/,stubs/a57c.interop diff --git a/c64/basic/a644.interop b/c64/basic/,stubs/a644.interop similarity index 100% rename from c64/basic/a644.interop rename to c64/basic/,stubs/a644.interop diff --git a/c64/basic/,stubs/a644.new.s b/c64/basic/,stubs/a644.new.s new file mode 100644 index 00000000..73c8df60 --- /dev/null +++ b/c64/basic/,stubs/a644.new.s @@ -0,0 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and real implementation + +new: + STUB_IMPLEMENTATION() diff --git a/c64/basic/a659.interop b/c64/basic/,stubs/a659.interop similarity index 100% rename from c64/basic/a659.interop rename to c64/basic/,stubs/a659.interop diff --git a/c64/basic/a659.setcharptr.s b/c64/basic/,stubs/a659.setcharptr.s similarity index 75% rename from c64/basic/a659.setcharptr.s rename to c64/basic/,stubs/a659.setcharptr.s index b7383332..64a573a3 100644 --- a/c64/basic/a659.setcharptr.s +++ b/c64/basic/,stubs/a659.setcharptr.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // XXX provide documentation and implementation // see: https://www.lemon64.com/forum/viewtopic.php?t=64721&sid=bc400a5a6d404f8f092e4d32a92f5de7 diff --git a/c64/basic/a71a.interop b/c64/basic/,stubs/a71a.interop similarity index 100% rename from c64/basic/a71a.interop rename to c64/basic/,stubs/a71a.interop diff --git a/c64/basic/,stubs/a71a.qplop.s b/c64/basic/,stubs/a71a.qplop.s new file mode 100644 index 00000000..921a807a --- /dev/null +++ b/c64/basic/,stubs/a71a.qplop.s @@ -0,0 +1,16 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Official BASIC routine, described in: +// +// - [RG64] C64 Programmers Reference Guide - XXX +// - [CM64] Computes Mapping the Commodore 64 - page 69, XXX +// +// CPU registers that has to be preserved (see [RG64]): XXX +// + + +QPLOP: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs/a7e4.gone.s b/c64/basic/,stubs/a7e4.gone.s new file mode 100644 index 00000000..bfbc4435 --- /dev/null +++ b/c64/basic/,stubs/a7e4.gone.s @@ -0,0 +1,16 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Official BASIC routine, described in: +// +// - [RG64] C64 Programmers Reference Guide - XXX +// - [CM64] Computes Mapping the Commodore 64 - page 70, XXX +// +// CPU registers that has to be preserved (see [RG64]): XXX +// + + +GONE: + STUB_IMPLEMENTATION() diff --git a/c64/basic/a7e4.interop b/c64/basic/,stubs/a7e4.interop similarity index 100% rename from c64/basic/a7e4.interop rename to c64/basic/,stubs/a7e4.interop diff --git a/c64/basic/,stubs/ad9e.frmevl.s b/c64/basic/,stubs/ad9e.frmevl.s new file mode 100644 index 00000000..2a246f66 --- /dev/null +++ b/c64/basic/,stubs/ad9e.frmevl.s @@ -0,0 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and implementation + +FRMEVL: + STUB_IMPLEMENTATION() diff --git a/c64/basic/ad9e.interop b/c64/basic/,stubs/ad9e.interop similarity index 100% rename from c64/basic/ad9e.interop rename to c64/basic/,stubs/ad9e.interop diff --git a/c64/basic/,stubs/ae86.eval.s b/c64/basic/,stubs/ae86.eval.s new file mode 100644 index 00000000..b8e06255 --- /dev/null +++ b/c64/basic/,stubs/ae86.eval.s @@ -0,0 +1,16 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Official BASIC routine, described in: +// +// - [RG64] C64 Programmers Reference Guide - XXX +// - [CM64] Computes Mapping the Commodore 64 - page 70, XXX +// +// CPU registers that has to be preserved (see [RG64]): XXX +// + + +EVAL: + STUB_IMPLEMENTATION() diff --git a/c64/basic/ae86.interop b/c64/basic/,stubs/ae86.interop similarity index 100% rename from c64/basic/ae86.interop rename to c64/basic/,stubs/ae86.interop diff --git a/c64/basic/,stubs/e38b.error.s b/c64/basic/,stubs/e38b.error.s new file mode 100644 index 00000000..e057f13a --- /dev/null +++ b/c64/basic/,stubs/e38b.error.s @@ -0,0 +1,16 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Official BASIC routine, described in: +// +// - [RG64] C64 Programmers Reference Guide - XXX +// - [CM64] Computes Mapping the Commodore 64 - page 69, XXX +// +// CPU registers that has to be preserved (see [RG64]): XXX +// + + +ERROR: + STUB_IMPLEMENTATION() diff --git a/c64/basic/e38b.interop b/c64/basic/,stubs/e38b.interop similarity index 100% rename from c64/basic/e38b.interop rename to c64/basic/,stubs/e38b.interop diff --git a/c64/basic/,stubs/e3bf.init.s b/c64/basic/,stubs/e3bf.init.s new file mode 100644 index 00000000..25cf67c0 --- /dev/null +++ b/c64/basic/,stubs/e3bf.init.s @@ -0,0 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and implementation + +INIT: + STUB_IMPLEMENTATION() diff --git a/c64/basic/e3bf.interop b/c64/basic/,stubs/e3bf.interop similarity index 100% rename from c64/basic/e3bf.interop rename to c64/basic/,stubs/e3bf.interop diff --git a/c64/basic/e453.interop b/c64/basic/,stubs/e453.interop similarity index 100% rename from c64/basic/e453.interop rename to c64/basic/,stubs/e453.interop diff --git a/c64/basic/,stubs/e453.rvect.s b/c64/basic/,stubs/e453.rvect.s new file mode 100644 index 00000000..b8322901 --- /dev/null +++ b/c64/basic/,stubs/e453.rvect.s @@ -0,0 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and implementation + +RVECT: + STUB_IMPLEMENTATION() diff --git a/c64/basic/a408.reason.s b/c64/basic/a408.reason.s deleted file mode 100644 index f7613215..00000000 --- a/c64/basic/a408.reason.s +++ /dev/null @@ -1,5 +0,0 @@ - -// XXX provide documentation and implementation - -REASON: - STUB_IMPLEMENTATION() diff --git a/c64/basic/a453.unknown.s b/c64/basic/a453.unknown.s deleted file mode 100644 index ecb53d23..00000000 --- a/c64/basic/a453.unknown.s +++ /dev/null @@ -1,4 +0,0 @@ - -// XXX provide documentation and implementation - - STUB_IMPLEMENTATION() \ No newline at end of file diff --git a/c64/basic/a483.main.s b/c64/basic/a483.main.s deleted file mode 100644 index 40415b24..00000000 --- a/c64/basic/a483.main.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// Official BASIC routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - XXX -// - [CM64] Compute's Mapping the Commodore 64 - page 69, XXX -// -// CPU registers that has to be preserved (see [RG64]): XXX -// - - -MAIN: - STUB_IMPLEMENTATION() diff --git a/c64/basic/a533.linkprg.s b/c64/basic/a533.linkprg.s index 675a794e..4db59db1 100644 --- a/c64/basic/a533.linkprg.s +++ b/c64/basic/a533.linkprg.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Well-known BASIC routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - page 95 +// - [CM64] Computes Mapping the Commodore 64 - page 95 // - https://www.lemon64.com/forum/viewtopic.php?t=64721&sid=bc400a5a6d404f8f092e4d32a92f5de7 // diff --git a/c64/basic/a57c.chrnch.s b/c64/basic/a57c.chrnch.s deleted file mode 100644 index 4f462ff6..00000000 --- a/c64/basic/a57c.chrnch.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// Official BASIC routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - XXX -// - [CM64] Compute's Mapping the Commodore 64 - page 69, XXX -// -// CPU registers that has to be preserved (see [RG64]): XXX -// - - -CHRNCH: - STUB_IMPLEMENTATION() diff --git a/c64/basic/a644.new.s b/c64/basic/a644.new.s deleted file mode 100644 index e4e54f59..00000000 --- a/c64/basic/a644.new.s +++ /dev/null @@ -1,5 +0,0 @@ - -// XXX provide documentation and real implementation - -new: - STUB_IMPLEMENTATION() diff --git a/c64/basic/a68e.runc.s b/c64/basic/a68e.runc.s index 5daa4b22..f0a8aeb1 100644 --- a/c64/basic/a68e.runc.s +++ b/c64/basic/a68e.runc.s @@ -1,7 +1,10 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // Well-known BASIC routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - page 97 +// - [CM64] Computes Mapping the Commodore 64 - page 97 // - https://www.c64-wiki.com/wiki/BASIC-ROM // - https://csdb.dk/forums/?roomid=11&topicid=137233 // @@ -13,7 +16,7 @@ RUNC: // But CSDB claims, that it should 'set current character pointer to start of basic - 1' - this // looks sane, also checked that the original BASIC routine does this (short test program) - // Let's initialize TXTPTR using TXTTAB + // Lets initialize TXTPTR using TXTTAB lda TXTTAB+0 sec diff --git a/c64/basic/a71a.qplop.s b/c64/basic/a71a.qplop.s deleted file mode 100644 index efa99f31..00000000 --- a/c64/basic/a71a.qplop.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// Official BASIC routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - XXX -// - [CM64] Compute's Mapping the Commodore 64 - page 69, XXX -// -// CPU registers that has to be preserved (see [RG64]): XXX -// - - -QPLOP: - STUB_IMPLEMENTATION() diff --git a/c64/basic/a7ae.newstt.s b/c64/basic/a7ae.newstt.s index 6dde6ca2..79aed4d6 100644 --- a/c64/basic/a7ae.newstt.s +++ b/c64/basic/a7ae.newstt.s @@ -1,18 +1,21 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // Well-known BASIC routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - page 97 +// - [CM64] Computes Mapping the Commodore 64 - page 97 // - https://www.lemon64.com/forum/viewtopic.php?t=64721&sid=bc400a5a6d404f8f092e4d32a92f5de7 // - https://www.lemon64.com/forum/viewtopic.php?t=70680&sid=3ff66caf7f5fdf2a3c2ff2ee31fc3fd8 // - https://codebase64.org/doku.php?id=base:assembling_your_own_cart_rom_image NEWSTT: - // XXX Real implementation is more complicated, it's actually a part + // XXX Real implementation is more complicated, it iss actually a part // of the BASIC main loop. It is, however, often called by various // utilities to simply run the software which was just loaded or // uncompressed. - // For now, let's cheat a little - this should provide some compatibility: + // For now, lets cheat a little - this should provide some compatibility: jmp cmd_run diff --git a/c64/basic/a7e4.gone.s b/c64/basic/a7e4.gone.s deleted file mode 100644 index 547f648a..00000000 --- a/c64/basic/a7e4.gone.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// Official BASIC routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - XXX -// - [CM64] Compute's Mapping the Commodore 64 - page 70, XXX -// -// CPU registers that has to be preserved (see [RG64]): XXX -// - - -GONE: - STUB_IMPLEMENTATION() diff --git a/c64/basic/ab1e.strout.s b/c64/basic/ab1e.strout.s index 4ad77a99..0317550a 100644 --- a/c64/basic/ab1e.strout.s +++ b/c64/basic/ab1e.strout.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Print string at $YYAA -// Compute's Mapping the 64 p101 +// Computes Mapping the 64 p101 // print string routine diff --git a/c64/basic/ad9e.frmevl.s b/c64/basic/ad9e.frmevl.s deleted file mode 100644 index 2b41983e..00000000 --- a/c64/basic/ad9e.frmevl.s +++ /dev/null @@ -1,5 +0,0 @@ - -// XXX provide documentation and implementation - -FRMEVL: - STUB_IMPLEMENTATION() diff --git a/c64/basic/ae86.eval.s b/c64/basic/ae86.eval.s deleted file mode 100644 index 423eb01a..00000000 --- a/c64/basic/ae86.eval.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// Official BASIC routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - XXX -// - [CM64] Compute's Mapping the Commodore 64 - page 70, XXX -// -// CPU registers that has to be preserved (see [RG64]): XXX -// - - -EVAL: - STUB_IMPLEMENTATION() diff --git a/c64/basic/basic_adray1.s b/c64/basic/basic_adray1.s index 879a6bce..201195a2 100644 --- a/c64/basic/basic_adray1.s +++ b/c64/basic/basic_adray1.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // XXX provide documentation and implementation diff --git a/c64/basic/basic_adray2.s b/c64/basic/basic_adray2.s index dbdd00c1..afb58e61 100644 --- a/c64/basic/basic_adray2.s +++ b/c64/basic/basic_adray2.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // XXX provide documentation and implementation diff --git a/c64/basic/basic_delete_line.s b/c64/basic/basic_delete_line.s index 33a3d5b5..d7491d1d 100644 --- a/c64/basic/basic_delete_line.s +++ b/c64/basic/basic_delete_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Delete the current BASIC line, which is assumed to have already // been found with basic_find_line. // Really only consists of copying memory down. diff --git a/c64/basic/basic_do_error.s b/c64/basic/basic_do_error.s index e4525fc6..084a8bea 100644 --- a/c64/basic/basic_do_error.s +++ b/c64/basic/basic_do_error.s @@ -1,4 +1,8 @@ -// Compute's Mapping the 64 p93 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// Computes Mapping the 64 p93 basic_do_error: // Save error number diff --git a/c64/basic/basic_execute_line.s b/c64/basic/basic_execute_line.s index e8c2c191..9268327a 100644 --- a/c64/basic/basic_execute_line.s +++ b/c64/basic/basic_execute_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Jump back into the BASIC execute line loop // after first checking that we have a colon // or $00 char @@ -87,7 +91,7 @@ basic_execute_statement: cmp #$7f bcc not_a_token - // It's a token: So get the jump table entry for it, push it on the stack + // It is a token: So get the jump table entry for it, push it on the stack // and then RTS to start it. asl tax @@ -112,7 +116,7 @@ not_a_token: cmp #$3a beq basic_skip_char - // If all else fails, it's a syntax error + // If all else fails, it is a syntax error jmp do_SYNTAX_error basic_skip_char: diff --git a/c64/basic/basic_find_line.s b/c64/basic/basic_find_line.s index 3f9ec214..45102507 100644 --- a/c64/basic/basic_find_line.s +++ b/c64/basic/basic_find_line.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // Find the BASIC line with number LINNUM diff --git a/c64/basic/basic_find_next_line.s b/c64/basic/basic_find_next_line.s index c3b86d1d..6c2cba88 100644 --- a/c64/basic/basic_find_next_line.s +++ b/c64/basic/basic_find_next_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Advance OLDTXT by following the // link to the next line diff --git a/c64/basic/basic_follow_link_to_next_line.s b/c64/basic/basic_follow_link_to_next_line.s index 1a9b138c..5a4acd2c 100644 --- a/c64/basic/basic_follow_link_to_next_line.s +++ b/c64/basic/basic_follow_link_to_next_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + basic_follow_link_to_next_line: ldy #0 diff --git a/c64/basic/basic_insert_line.s b/c64/basic/basic_insert_line.s index 17153e32..25212e01 100644 --- a/c64/basic/basic_insert_line.s +++ b/c64/basic/basic_insert_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Insert the tokenised line stored at $0200. // First work out where in the list to put it // (basic_find_line with the line number can be used to work diff --git a/c64/basic/basic_main_loop.s b/c64/basic/basic_main_loop.s index 55ea6dce..8e880687 100644 --- a/c64/basic/basic_main_loop.s +++ b/c64/basic/basic_main_loop.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + basic_main_loop: // XXX - Check if direct or program mode, and get next line of input @@ -24,7 +29,7 @@ read_line_loop: // Not carriage return, so try to append to line so far cpx #80 bcc !+ - // Report STRING TOO LONG error (Compute's Mapping the 64 p93) + // Report STRING TOO LONG error (Computes Mapping the 64 p93) ldx #22 jmp basic_do_error !: @@ -73,11 +78,11 @@ rsl_l1: #if CONFIG_DOS_WEDGE cmp #$40 // '@' - beq_far wedge_dos + beq_16 wedge_dos #endif #if CONFIG_TAPE_WEDGE cmp #$1F // left arrow - beq_far wedge_tape + beq_16 wedge_tape #endif #endif @@ -168,7 +173,7 @@ not_a_line: // Put invalid line number in current line number value, // so that we know we are in direct mode - // (Compute's Mapping the 64 p19) + // (Computes Mapping the 64 p19) lda #$FF sta CURLIN+1 diff --git a/c64/basic/basic_parse_line_number.s b/c64/basic/basic_parse_line_number.s index c4b9910f..3e8b8ce7 100644 --- a/c64/basic/basic_parse_line_number.s +++ b/c64/basic/basic_parse_line_number.s @@ -1,4 +1,8 @@ - +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + basic_parse_line_number: jsr injest_number diff --git a/c64/basic/basic_shift_mem_down.s b/c64/basic/basic_shift_mem_down.s index 8c9f5a15..0ab14abd 100644 --- a/c64/basic/basic_shift_mem_down.s +++ b/c64/basic/basic_shift_mem_down.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + basic_shift_mem_down_and_relink: // Shift memory down to basic_current_line_pointer // from X bytes further along. @@ -168,4 +173,3 @@ relink_down_loop: clc rts - diff --git a/c64/basic/basic_shift_mem_up.s b/c64/basic/basic_shift_mem_up.s index e01870a6..3ff1eb07 100644 --- a/c64/basic/basic_shift_mem_up.s +++ b/c64/basic/basic_shift_mem_up.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE basic_shift_mem_up_and_relink: diff --git a/c64/basic/basic_vector_defaults.s b/c64/basic/basic_vector_defaults.s index a12d2275..9e7ebb73 100644 --- a/c64/basic/basic_vector_defaults.s +++ b/c64/basic/basic_vector_defaults.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Default values for BASIC vectors - described in: // -// - [RG64] C64 Programmer's Reference Guide - pages 68-70 -// - [CM64] Compute's Mapping the Commodore 64 - page 318 +// - [RG64] C64 Programmers Reference Guide - pages 68-70 +// - [CM64] Computes Mapping the Commodore 64 - page 318 // basic_vector_defaults_1: diff --git a/c64/basic/bdcd.linprt.s b/c64/basic/bdcd.linprt.s index 7e58bebe..284b626e 100644 --- a/c64/basic/bdcd.linprt.s +++ b/c64/basic/bdcd.linprt.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Well-known BASIC routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - page 116, XXX +// - [CM64] Computes Mapping the Commodore 64 - page 116, XXX // diff --git a/c64/basic/c000.skip_gap.s b/c64/basic/c000.skip_gap.s index 3ad7357c..9d256aeb 100644 --- a/c64/basic/c000.skip_gap.s +++ b/c64/basic/c000.skip_gap.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // Skip the gap between $C000-$DFFF .fill $2000, $00 diff --git a/c64/basic/commands/cmd_break.s b/c64/basic/commands/cmd_break.s index 82909193..ee1a5768 100644 --- a/c64/basic/commands/cmd_break.s +++ b/c64/basic/commands/cmd_break.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + cmd_stop: ldx #30 // "BREAK" jsr print_packed_message diff --git a/c64/basic/commands/cmd_list.s b/c64/basic/commands/cmd_list.s index 6cf022e5..973ebc89 100644 --- a/c64/basic/commands/cmd_list.s +++ b/c64/basic/commands/cmd_list.s @@ -1,5 +1,10 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // LIST basic text. -// XXX - Doesn't currently support line number ranges +// XXX - Does not currently support line number ranges cmd_list: @@ -125,7 +130,6 @@ list_not_quote: bne list_not_rem // REM command locks quote flag on until the end of the line, allowing // funny characters in REM statements without problem. - inc $0427 sta QTSW // Any value other than $00 or $FF will lock quote mode on, so the token value of REM is fine here // FALL THROUGH list_not_rem: @@ -146,5 +150,3 @@ list_is_literal: list_end_of_line: // Print end of line jmp print_return - - diff --git a/c64/basic/commands/cmd_load.s b/c64/basic/commands/cmd_load.s index 20e2a501..17f1fee7 100644 --- a/c64/basic/commands/cmd_load.s +++ b/c64/basic/commands/cmd_load.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + cmd_load: // Parse filename @@ -7,7 +12,7 @@ cmd_load: // Parse optional device # // Parse optional secondary address - // XXX - C64 BASIC apparently doesn't clear variables after a LOAD in the + // XXX - C64 BASIC apparently does not clear variables after a LOAD in the // middle of a program. For safety, we do. jsr basic_do_clr @@ -77,7 +82,7 @@ got_devicenumber: sta SA jmp cmd_load_got_secondaryaddress !: - // Second parameter is above 255, this can't be a secondary address + // Second parameter is above 255, this can not be a secondary address // Use it as load address instead // XXX temporary syntax, it would be better to use something // XXX like 'LOAD"FILE",8 TO 49152' diff --git a/c64/basic/commands/cmd_new.s b/c64/basic/commands/cmd_new.s index 2c3102bf..fc455a77 100644 --- a/c64/basic/commands/cmd_new.s +++ b/c64/basic/commands/cmd_new.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + cmd_new: jsr basic_do_new diff --git a/c64/basic/commands/cmd_rem.s b/c64/basic/commands/cmd_rem.s index 24af2e0b..c8b9b021 100644 --- a/c64/basic/commands/cmd_rem.s +++ b/c64/basic/commands/cmd_rem.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // REM statement just skips to the next line cmd_rem: diff --git a/c64/basic/commands/cmd_run.s b/c64/basic/commands/cmd_run.s index 6e718c81..e37f7854 100644 --- a/c64/basic/commands/cmd_run.s +++ b/c64/basic/commands/cmd_run.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + cmd_run: // RUN clears all variables jsr basic_do_clr @@ -15,7 +20,7 @@ cmd_goto: jsr basic_parse_line_number jsr basic_find_line bcc !+ - // Line doesn't exist, so report error + // Line does not exist, so report error jmp do_UNDEFD_STATEMENT_error !: // Run it! diff --git a/c64/basic/commands/cmd_sys.s b/c64/basic/commands/cmd_sys.s index 9f1c637c..2278aafc 100644 --- a/c64/basic/commands/cmd_sys.s +++ b/c64/basic/commands/cmd_sys.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + cmd_sys: jsr basic_end_of_statement_check diff --git a/c64/basic/commands/cmd_unimplemented.s b/c64/basic/commands/cmd_unimplemented.s index ffdffd96..59407688 100644 --- a/c64/basic/commands/cmd_unimplemented.s +++ b/c64/basic/commands/cmd_unimplemented.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // // Default handler for all not-yet-implemented commands // diff --git a/c64/basic/do_basic_error.s b/c64/basic/do_basic_error.s index 1135e102..6bf58362 100644 --- a/c64/basic/do_basic_error.s +++ b/c64/basic/do_basic_error.s @@ -1,4 +1,8 @@ -// As many errors are triggered from many places in the BASIC +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// As many errors are triggered from many places in the BASIC // interprettor, it is important to have an efficicent means of // calling them. // LDX #$nn / jmp do_basic_error diff --git a/c64/basic/e38b.error.s b/c64/basic/e38b.error.s deleted file mode 100644 index 43954f1d..00000000 --- a/c64/basic/e38b.error.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// Official BASIC routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - XXX -// - [CM64] Compute's Mapping the Commodore 64 - page 69, XXX -// -// CPU registers that has to be preserved (see [RG64]): XXX -// - - -ERROR: - STUB_IMPLEMENTATION() diff --git a/c64/basic/e3bf.init.s b/c64/basic/e3bf.init.s deleted file mode 100644 index 884154f6..00000000 --- a/c64/basic/e3bf.init.s +++ /dev/null @@ -1,5 +0,0 @@ - -// XXX provide documentation and implementation - -INIT: - STUB_IMPLEMENTATION() diff --git a/c64/basic/e453.rvect.s b/c64/basic/e453.rvect.s deleted file mode 100644 index 916e26fd..00000000 --- a/c64/basic/e453.rvect.s +++ /dev/null @@ -1,5 +0,0 @@ - -// XXX provide documentation and implementation - -RVECT: - STUB_IMPLEMENTATION() diff --git a/c64/basic/fac1_mul.s b/c64/basic/fac1_mul.s index 4b60948f..b69f9714 100644 --- a/c64/basic/fac1_mul.s +++ b/c64/basic/fac1_mul.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Multiply Floating Point Accumulator by 10 // = 8x + 2x // Implement by shifting MAC left one bit, diff --git a/c64/basic/init/a000.cold_start_vector.s b/c64/basic/init/a000.cold_start_vector.s index 7ed2cb76..067b0f64 100644 --- a/c64/basic/init/a000.cold_start_vector.s +++ b/c64/basic/init/a000.cold_start_vector.s @@ -1,4 +1,8 @@ -// Compute's Mapping the C64 p88 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// Computes Mapping the C64 p88 .word basic_cold_start - diff --git a/c64/basic/init/a002.warm_start_vector.s b/c64/basic/init/a002.warm_start_vector.s index 63c4d2a5..411e17a5 100644 --- a/c64/basic/init/a002.warm_start_vector.s +++ b/c64/basic/init/a002.warm_start_vector.s @@ -1,3 +1,8 @@ -// Compute's Mapping the C64 p88 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// Computes Mapping the C64 p88 .word basic_warm_start diff --git a/c64/basic/init/basic_cold_start_internal.s b/c64/basic/init/basic_cold_start_internal.s index a7326089..e321d9e7 100644 --- a/c64/basic/init/basic_cold_start_internal.s +++ b/c64/basic/init/basic_cold_start_internal.s @@ -1,8 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Continuation of the BASIC cold start routine // + basic_cold_start_internal: // Setup vectors at $300 @@ -29,6 +33,11 @@ basic_cold_start_internal: lda #>do_ILLEGAL_QUANTITY_error sta USRADD+1 + // Clear the BRK location address + lda #$00 + sta CMP0+0 + sta CMP0+1 + // Print startup messages jsr INITMSG diff --git a/c64/basic/init/basic_warm_start_internal.s b/c64/basic/init/basic_warm_start_internal.s index b271b928..f9ad47c0 100644 --- a/c64/basic/init/basic_warm_start_internal.s +++ b/c64/basic/init/basic_warm_start_internal.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Continuation of the BASIC cold start routine diff --git a/c64/basic/init/e394.basic_cold_start.s b/c64/basic/init/e394.basic_cold_start.s index fe181381..76419f1c 100644 --- a/c64/basic/init/e394.basic_cold_start.s +++ b/c64/basic/init/e394.basic_cold_start.s @@ -1,5 +1,10 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // BASIC Cold start entry point -// Compute's Mapping the 64 p211 +// Computes Mapping the 64 p211 basic_cold_start: @@ -17,6 +22,6 @@ basic_cold_start: dey bpl !-- - // Remaining part wouldn't fit here + // Remaining part would not fit here jmp basic_cold_start_internal diff --git a/c64/basic/init/e3b7.basic_warm_start.jmp.s b/c64/basic/init/e3b7.basic_warm_start.jmp.s index 8ebcfbde..144ba4b6 100644 --- a/c64/basic/init/e3b7.basic_warm_start.jmp.s +++ b/c64/basic/init/e3b7.basic_warm_start.jmp.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // Clear screen etc, show READY prompt. basic_warm_start: diff --git a/c64/basic/init/e422.initmsg.jmp.s b/c64/basic/init/e422.initmsg.jmp.s index 5bb33656..9d69690f 100644 --- a/c64/basic/init/e422.initmsg.jmp.s +++ b/c64/basic/init/e422.initmsg.jmp.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Well-known BASIC routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - page 212 +// - [CM64] Computes Mapping the Commodore 64 - page 212 // // Prints the start-up messages // diff --git a/c64/basic/init/initmsg_bytes_free.s b/c64/basic/init/initmsg_bytes_free.s index d4df557c..ee2c4fa5 100644 --- a/c64/basic/init/initmsg_bytes_free.s +++ b/c64/basic/init/initmsg_bytes_free.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print out the amount of free bytes - for the startup banner diff --git a/c64/basic/init/initmsg_real.s b/c64/basic/init/initmsg_real.s index 923b74a6..15ca951c 100644 --- a/c64/basic/init/initmsg_real.s +++ b/c64/basic/init/initmsg_real.s @@ -1,9 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Routine is too long to fit in the original location initmsg_real: + // Clear the screen first, some cartridges (like IEEE-488) leeave a mess on the screen + lda #147 + jsr JCHROUT + #if CONFIG_BANNER_SIMPLE lda #startup_banner jsr STROUT - ldx #$04 + ldx #$05 ldy #$00 jsr plot_set @@ -126,20 +134,20 @@ initmsg_real: ldy #>rom_revision_basic_string jsr STROUT - ldx #$04 + ldx #$05 ldy #$12 jsr plot_set jsr initmsg_bytes_free #if CONFIG_SHOW_FEATURES - ldx #$05 + ldx #$08 ldy #$00 jsr plot_set jsr print_features jmp print_return #else - ldx #$05 + ldx #$08 ldy #$00 jmp plot_set #endif diff --git a/c64/basic/init/startup_banner.s b/c64/basic/init/startup_banner.s index 7543ef0a..faedc2c3 100644 --- a/c64/basic/init/startup_banner.s +++ b/c64/basic/init/startup_banner.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // Startup banner, to be displayed during cold start diff --git a/c64/basic/init_oldtxt.s b/c64/basic/init_oldtxt.s index 6becf049..9879e463 100644 --- a/c64/basic/init_oldtxt.s +++ b/c64/basic/init_oldtxt.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + init_oldtxt: diff --git a/c64/basic/injest_comma.s b/c64/basic/injest_comma.s index 06e50338..2e59ead9 100644 --- a/c64/basic/injest_comma.s +++ b/c64/basic/injest_comma.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Consummes a comma in a BASIC code, C set for no coma found diff --git a/c64/basic/injest_number.s b/c64/basic/injest_number.s index 6266e036..8fef2c70 100644 --- a/c64/basic/injest_number.s +++ b/c64/basic/injest_number.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + // Parse a number from the input buffer at (TXTPTR) // Result is put into FAC1. // TXTPTR is updated with first position after the number. @@ -5,7 +10,7 @@ // XXX - Remember decimal position and exponent, and apply them // after to produce normalised floating point number. -// XXX - Doesn't use routines to access memory under ROMs etc. +// XXX - Does not use routines to access memory under ROMs etc. // This is important, because this routine operates on numbers in BASIC text. ij_not_a_digit: @@ -127,7 +132,7 @@ ij_loop2: // Carry set, so we have overflowed. // We should shift everything right one digit, and increase // the exponent by one. The non-zero exponent tells us that we - // can't fit any more precision in. + // can not fit any more precision in. jsr fac1_mantissa_div2 !: @@ -149,5 +154,3 @@ erase_fac1: sta FACOV rts - - diff --git a/c64/basic/pack_word.s b/c64/basic/pack_word.s index b332d8e2..5b8e502e 100644 --- a/c64/basic/pack_word.s +++ b/c64/basic/pack_word.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Pack a word using the simple compression scheme. // This has to be the same implementation as in compress_text.c // because we compress input lines of BASIC to do the tokenisation. diff --git a/c64/basic/peek_line_pointer_null_check.s b/c64/basic/peek_line_pointer_null_check.s index e71a8d56..d3368be5 100644 --- a/c64/basic/peek_line_pointer_null_check.s +++ b/c64/basic/peek_line_pointer_null_check.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Return C=1 if a pointer in BASIC memory space is NULL, else C=0 // X = ZP pointer to check diff --git a/c64/basic/print_integer.s b/c64/basic/print_integer.s index 47d58223..72c0f68a 100644 --- a/c64/basic/print_integer.s +++ b/c64/basic/print_integer.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Works similar to $BDCD in original C64 BASIC // XXX Should eventually get replaced by a more flexible and optimal routine. // Temp result gets written to $0100-$0104 diff --git a/c64/basic/print_packed_message.s b/c64/basic/print_packed_message.s index efed0e6a..8aba8b25 100644 --- a/c64/basic/print_packed_message.s +++ b/c64/basic/print_packed_message.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // This routine prints messages that have been packed // using the make_error_tables program. // The general idea is to save space in the ROM. @@ -30,22 +34,34 @@ packed_message_search: sec rts -found_message_in_token_stream: +found_message_in_token_stream: // XXX size-optimize this // Now print each word in the message phy_trash_a lda packed_message_tokens,y - cmp #$ff - beq !+ + cmp #$FF + beq found_message_in_token_stream_done + jsr print_packed_word - jsr print_space ply_trash_a iny - bne found_message_in_token_stream + beq found_message_in_token_stream_done !: + phy_trash_a + lda packed_message_tokens,y + cmp #$FF + beq found_message_in_token_stream_done + + pha + jsr print_space + pla + + jsr print_packed_word + ply_trash_a + iny + bne !- + +found_message_in_token_stream_done: pla - // Rub out space at the end - lda #$14 - jsr JCHROUT rts print_packed_word: @@ -93,7 +109,7 @@ packed_word_search: found_packed_word: // Get pointer to start of packed word - // Make sure we don't wrap on a page boundary + // Make sure we do not wrap on a page boundary tya clc adc FRESPC+0 @@ -136,15 +152,11 @@ next_packed_word_char: lsr tax - // Save Y so it doesn't get clobbered by CHROUT - phy_trash_a - // X=1-14 = first 14 chars, so subtract one lda packed_message_chars-1,x - jsr JCHROUT + jsr JCHROUT // preserves .Y // See if there is a char in the low nybl to print - ply_trash_a lda (FRESPC),y and #$0f beq end_of_packed_word diff --git a/c64/basic/ready_message.s b/c64/basic/ready_message.s index 3a349177..791cb7eb 100644 --- a/c64/basic/ready_message.s +++ b/c64/basic/ready_message.s @@ -1,6 +1,10 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + ready_message: // See src/make_error_tables.c for packed message handling // information. ldx #29 jmp print_packed_message - diff --git a/c64/basic/rom_revision/a004.identifier.s b/c64/basic/rom_revision/a004.identifier.s index 88cbb600..2edea486 100644 --- a/c64/basic/rom_revision/a004.identifier.s +++ b/c64/basic/rom_revision/a004.identifier.s @@ -1,6 +1,10 @@ -// Compute's Mapping the 64, p89 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// Computes Mapping the 64, p89 // 8 character name // MEGABAS2 = "MEGA BASIC 2" .byte $4D,$45,$47,$41,$42,$41,$53,$32 - diff --git a/c64/basic/rom_revision/bf52.rom_revision_basic.s b/c64/basic/rom_revision/bf52.rom_revision_basic.s index 8fe574c8..91438dac 100644 --- a/c64/basic/rom_revision/bf52.rom_revision_basic.s +++ b/c64/basic/rom_revision/bf52.rom_revision_basic.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // !!! PROPOSAL ONLY !!! PROPOSAL ONLY !!! NOT FOR USING EXTERNALLY YET !!! @@ -6,7 +9,7 @@ // Do not change! Locations of the following data should be constant - now and forever! // // If you want to integrate Open ROMs support in your emulator, FPGA ccomputer, etc. - this -// is the official way to recognize the ROM and it's revision. +// is the official way to recognize the ROM and its revision. // diff --git a/c64/basic/rom_revision/e4b7.rom_revision_kernal.s b/c64/basic/rom_revision/e4b7.rom_revision_kernal.s index e98bb1a8..e9254347 100644 --- a/c64/basic/rom_revision/e4b7.rom_revision_kernal.s +++ b/c64/basic/rom_revision/e4b7.rom_revision_kernal.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE // // !!! PROPOSAL ONLY !!! PROPOSAL ONLY !!! NOT FOR USING EXTERNALLY YET !!! @@ -6,14 +9,14 @@ // Do not change! Locations of the following data should be constant - now and forever! // // If you want to integrate Open ROMs support in your emulator, FPGA ccomputer, etc. - this -// is the official way to recognize the ROM and it's revision. +// is the official way to recognize the ROM and its revision. // // $E4B7 // This vector is to be used by non-Kernal ROMs, if they want to - // complain about incompatible ROM releases - don't use it directly, + // complain about incompatible ROM releases - do not use it directly, // use a 'panic' pseudocommand with error code (will be passed using .A) // #P_ERR_ROM_MISMATCH - it should remain stable even between releases diff --git a/c64/basic/select_device.s b/c64/basic/select_device.s index 6d9a2e76..ba23425d 100644 --- a/c64/basic/select_device.s +++ b/c64/basic/select_device.s @@ -1,7 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + select_device: - // Take last device number, make sure it's a drive - 8 or above. Above 30, + // Take last device number, make sure it is a drive - 8 or above. Above 30, // although illegal for IEC we also consider a drive, as they exists // drivers assigning these numbers to CBM-DOS capable devices - like some // IEEE-488 carts. @@ -9,8 +13,6 @@ select_device: // If current device is not a drive, set device to 8 (first drive number) // Device number is left in X, for SETFLS Kernal routine - // Note: if tape support is introduced here, make sure DOS wedge won't get broken - ldx FA cpx #$08 bcs !+ diff --git a/c64/basic/tokenise_line.s b/c64/basic/tokenise_line.s index 7a642834..0c54eed7 100644 --- a/c64/basic/tokenise_line.s +++ b/c64/basic/tokenise_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // Tokenise a line of BASIC // Stored at $0200 // Length in __tokenise_work1 @@ -266,4 +270,3 @@ done_searching_for_token: sec lda #$00 rts - diff --git a/c64/basic/under_rom_routines.s b/c64/basic/under_rom_routines.s index 1027e57a..611b7e65 100644 --- a/c64/basic/under_rom_routines.s +++ b/c64/basic/under_rom_routines.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + // IMPORTANT: // These routines lengths cannot be changed without changing // the aliases for peek_under_roms, poke_under_roms etc diff --git a/c64/basic/wedge_dos.s b/c64/basic/wedge_dos.s index b7292c5d..7b7db2a6 100644 --- a/c64/basic/wedge_dos.s +++ b/c64/basic/wedge_dos.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + #if CONFIG_DOS_WEDGE diff --git a/c64/basic/wedge_tape.s b/c64/basic/wedge_tape.s index 4edbe8e8..ffc41f27 100644 --- a/c64/basic/wedge_tape.s +++ b/c64/basic/wedge_tape.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + #if CONFIG_TAPE_WEDGE @@ -10,11 +14,11 @@ wedge_tape: sta CURLIN+1 // in case of error do not print line number cpx #$02 - bne_far do_SYNTAX_error + bne_16 do_SYNTAX_error lda BUF+1 cmp #$4C // 'L' - bne_far do_SYNTAX_error + bne_16 do_SYNTAX_error // Execute 'arrow + L' diff --git a/c64/kernal/,disabled/u64_load.s b/c64/kernal/,disabled/u64_load.s index 7b585c1e..6d1d916a 100644 --- a/c64/kernal/,disabled/u64_load.s +++ b/c64/kernal/,disabled/u64_load.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // LOAD routine hook for fast loading via UltiDOS diff --git a/c64/kernal/,stubs/e566.home_cursor.s b/c64/kernal/,stubs/e566.home_cursor.s deleted file mode 100644 index 4e5b7d5f..00000000 --- a/c64/kernal/,stubs/e566.home_cursor.s +++ /dev/null @@ -1,4 +0,0 @@ - -// XXX provide documentation and implementation - - STUB_IMPLEMENTATION() diff --git a/c64/kernal/,stubs/e6b6.advance_cursor.s b/c64/kernal/,stubs/e6b6.advance_cursor.s index 4e5b7d5f..22378e62 100644 --- a/c64/kernal/,stubs/e6b6.advance_cursor.s +++ b/c64/kernal/,stubs/e6b6.advance_cursor.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // XXX provide documentation and implementation diff --git a/c64/kernal/,stubs/e701.previous_line.s b/c64/kernal/,stubs/e701.previous_line.s index 4e5b7d5f..22378e62 100644 --- a/c64/kernal/,stubs/e701.previous_line.s +++ b/c64/kernal/,stubs/e701.previous_line.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // XXX provide documentation and implementation diff --git a/c64/kernal/,stubs/e716.chrout_screen.s b/c64/kernal/,stubs/e716.chrout_screen.s index 423ed67b..98e607bb 100644 --- a/c64/kernal/,stubs/e716.chrout_screen.s +++ b/c64/kernal/,stubs/e716.chrout_screen.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Screen CHROUT diff --git a/c64/kernal/,stubs/e8ea.scroll_line.s b/c64/kernal/,stubs/e8ea.scroll_line.s deleted file mode 100644 index 4e5b7d5f..00000000 --- a/c64/kernal/,stubs/e8ea.scroll_line.s +++ /dev/null @@ -1,4 +0,0 @@ - -// XXX provide documentation and implementation - - STUB_IMPLEMENTATION() diff --git a/c64/kernal/,stubs/e96c.insert_line_at_top.s b/c64/kernal/,stubs/e96c.insert_line_at_top.s index f28c13c4..bdb40c9d 100644 --- a/c64/kernal/,stubs/e96c.insert_line_at_top.s +++ b/c64/kernal/,stubs/e96c.insert_line_at_top.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Insert line at top of screen diff --git a/c64/kernal/,stubs/e9ff.clear_line.s b/c64/kernal/,stubs/e9ff.clear_line.s deleted file mode 100644 index 4e5b7d5f..00000000 --- a/c64/kernal/,stubs/e9ff.clear_line.s +++ /dev/null @@ -1,4 +0,0 @@ - -// XXX provide documentation and implementation - - STUB_IMPLEMENTATION() diff --git a/c64/kernal/,stubs/f3f6.interop b/c64/kernal/,stubs/f3f6.interop new file mode 100644 index 00000000..fc5d3109 --- /dev/null +++ b/c64/kernal/,stubs/f3f6.interop @@ -0,0 +1 @@ +Routine is called by Lemmings game, purpose unknown so far diff --git a/c64/kernal/,stubs/f3f6.unknown.s b/c64/kernal/,stubs/f3f6.unknown.s new file mode 100644 index 00000000..22378e62 --- /dev/null +++ b/c64/kernal/,stubs/f3f6.unknown.s @@ -0,0 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// XXX provide documentation and implementation + + STUB_IMPLEMENTATION() diff --git a/c64/kernal/,stubs/f646.iec_close.s b/c64/kernal/,stubs/f646.iec_close.s index d4d05036..5bd31cbd 100644 --- a/c64/kernal/,stubs/f646.iec_close.s +++ b/c64/kernal/,stubs/f646.iec_close.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // IEC close diff --git a/c64/kernal/,stubs/fd90.unknown.s b/c64/kernal/,stubs/fd90.unknown.s index 4e5b7d5f..22378e62 100644 --- a/c64/kernal/,stubs/fd90.unknown.s +++ b/c64/kernal/,stubs/fd90.unknown.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // XXX provide documentation and implementation diff --git a/c64/kernal/assets/cartridge_signature.s b/c64/kernal/assets/cartridge_signature.s index 2b0c5f90..c6aabb98 100644 --- a/c64/kernal/assets/cartridge_signature.s +++ b/c64/kernal/assets/cartridge_signature.s @@ -1,3 +1,9 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) + cartridge_signature: + .byte $C3,$C2,$CD,$38,$30 + + +#endif // ROM layout diff --git a/c64/kernal/assets/e8da.colour_codes.s b/c64/kernal/assets/e8da.colour_codes.s index fdf0b980..89849a12 100644 --- a/c64/kernal/assets/e8da.colour_codes.s +++ b/c64/kernal/assets/e8da.colour_codes.s @@ -1,6 +1,10 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) // CHR$ codes for the 16 colours colour_codes: .byte 144,5,28,159,156,30,31,158 .byte 129,149,150,151,152,153,154,155 + + +#endif // ROM layout diff --git a/c64/kernal/assets/fd30.vector_defaults.s b/c64/kernal/assets/fd30.vector_defaults.s index dd7fa89d..13b01e78 100644 --- a/c64/kernal/assets/fd30.vector_defaults.s +++ b/c64/kernal/assets/fd30.vector_defaults.s @@ -1,9 +1,10 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) // // Default values for Kernal vectors - described in: // -// - [RG64] C64 Programmer's Reference Guide - page 293 (RESTOR), 304 (VECTOR) -// - [CM64] Compute's Mapping the Commodore 64 - page 237 +// - [RG64] C64 Programmers Reference Guide - page 293 (RESTOR), 304 (VECTOR) +// - [CM64] Computes Mapping the Commodore 64 - page 237 // vector_defaults: @@ -24,3 +25,6 @@ vector_defaults: .word default_brk_handler // USRCMD .word LOAD // ILOAD .word SAVE // ISAVE + + +#endif // ROM layout diff --git a/c64/kernal/assets/irq_timing_hi.s b/c64/kernal/assets/irq_timing_hi.s new file mode 100644 index 00000000..794dd5cb --- /dev/null +++ b/c64/kernal/assets/irq_timing_hi.s @@ -0,0 +1,27 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) + +// +// Values for IRQ generation timer - original idea was: +// +// (This value was calculated by running a custom IRQ handler on a C64 +// with original KERNAL, and writing the values of $DC04/5 to the screen +// in the IRQ handler to see roughly what value the timers must be set to) +// ldy #<16380 +// ldx #>16380 + +// Current values selected on the following assumptions: +// +// PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), +// is clocked at 0.985248 MHz, so that 1/60s is 16421 ($4025) CPU cycles +// +// NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), +// is clocked at 1.022727 MHz, so that 1/60s is 17045 ($4295) CPU cycles + + +irq_timing_hi: // high bytes + + .byte >17045 // NTSC + .byte >16421 // PAL + + +#endif // ROM layout diff --git a/c64/kernal/assets/irq_timing_lo.s b/c64/kernal/assets/irq_timing_lo.s new file mode 100644 index 00000000..2d18d4ec --- /dev/null +++ b/c64/kernal/assets/irq_timing_lo.s @@ -0,0 +1,27 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) + +// +// Values for IRQ generation timer - original idea was: +// +// (This value was calculated by running a custom IRQ handler on a C64 +// with original KERNAL, and writing the values of $DC04/5 to the screen +// in the IRQ handler to see roughly what value the timers must be set to) +// ldy #<16380 +// ldx #>16380 + +// Current values selected on the following assumptions: +// +// PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), +// is clocked at 0.985248 MHz, so that 1/60s is 16421 ($4025) CPU cycles +// +// NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), +// is clocked at 1.022727 MHz, so that 1/60s is 17045 ($4295) CPU cycles + + +irq_timing_lo: // low bytes + + .byte <17045 // NTSC + .byte <16421 // PAL + + +#endif // ROM layout \ No newline at end of file diff --git a/c64/kernal/assets/kernal_messages.s b/c64/kernal/assets/kernal_messages.s index a14954c1..5f7712b1 100644 --- a/c64/kernal/assets/kernal_messages.s +++ b/c64/kernal/assets/kernal_messages.s @@ -1,3 +1,4 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) // // Messages to be prined out by Kernal @@ -110,3 +111,6 @@ __msg_kernalfeatures: .byte $80 + $0D // end of string mark + return #endif // CONFIG_SHOW_FEATURES + + +#endif // ROM layout diff --git a/c64/kernal/banking/4000.interop b/c64/kernal/banking/4000.interop new file mode 100644 index 00000000..7b399af5 --- /dev/null +++ b/c64/kernal/banking/4000.interop @@ -0,0 +1 @@ +This particular address is not for interoperability - we had to choose some fixed location foor the extended ROM jumptable, beginning of the mapped memory block is just sane. diff --git a/c64/kernal/banking/4000.mega65_jumptable_kernal_1.s b/c64/kernal/banking/4000.mega65_jumptable_kernal_1.s new file mode 100644 index 00000000..001d624e --- /dev/null +++ b/c64/kernal/banking/4000.mega65_jumptable_kernal_1.s @@ -0,0 +1,26 @@ +// #LAYOUT# M65 KERNAL_0 #TAKE-FLOAT +// #LAYOUT# M65 KERNAL_1 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Definitions for communication with Mega65 segment KERNAL_1 +// + + +#if SEGMENT_KERNAL_0 + + // Labels for jumps + + + .label KERNAL_1__RAMTAS = $4000 + + +#else + + // Jumptable (OpenROMs private!) + + + jmp RAMTAS + + +#endif diff --git a/c64/kernal/banking/mega65_map_helpers.s b/c64/kernal/banking/mega65_map_helpers.s new file mode 100644 index 00000000..0009100f --- /dev/null +++ b/c64/kernal/banking/mega65_map_helpers.s @@ -0,0 +1,56 @@ +// #LAYOUT# M65 KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// ROM mapping routines for Mega65 +// + +// Available memory maps: +// - NORMAL - nothing mapped in +// - KERNAL_1 - for calling KERNAL_1 segment code + + +map_NORMAL: + + php + pha + phx + phy + phz + + lda #$00 + tax + tay + taz + + // FALLTROUGH + +map_end: + + map + eom + + plz + ply + plx + pla + plp + + rts + + +map_KERNAL_1: + + php + pha + phx + phy + phz + + lda #$00 + tay + taz + + ldx #$42 // 0x4000 <- map 8KB from 0x20000 + + bne map_end diff --git a/c64/kernal/errors.s b/c64/kernal/errors.s index 73e6c552..91a85fe0 100644 --- a/c64/kernal/errors.s +++ b/c64/kernal/errors.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE -// Kernal error codes are described in 'Commodore 64 Programmer's Reference Guide', page 306 + +// Kernal error codes are described in 'Commodore 64 Programmers Reference Guide', page 306 kernalerror_ROUTINE_TERMINATED: // by a STOP key lda #K_ERR_ROUTINE_TERMINATED @@ -56,14 +60,15 @@ kernalerror_TOP_MEM_RS232: sec rts -// Kernal status codes are described in 'Commodore 64 Programmer's Reference Guide', page 292 + +// Kernal status codes are described in 'Commodore 64 Programmers Reference Guide', page 292 kernalstatus_reset: lda #$00 sta IOSTATUS rts -// The following two statuses are currentl not implemented - and most likely not really needed +// The following two statuses are currently not implemented - and most likely not really needed // kernalstatus_TIMEOUT_WRITE: // lda IOSTATUS diff --git a/c64/kernal/iec/acptr.s b/c64/kernal/iec/acptr.s index 2ed7962d..4739e5db 100644 --- a/c64/kernal/iec/acptr.s +++ b/c64/kernal/iec/acptr.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 274 -// - [CM64] Compute's Mapping the Commodore 64 - page 224/225 +// - [RG64] C64 Programmers Reference Guide - page 274 +// - [CM64] Computes Mapping the Commodore 64 - page 224/225 // // CPU registers that has to be preserved (see [RG64]): .Y // diff --git a/c64/kernal/iec/chkin_iec.s b/c64/kernal/iec/chkin_iec.s index b86dee9c..c63e424a 100644 --- a/c64/kernal/iec/chkin_iec.s +++ b/c64/kernal/iec/chkin_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the CHKIN routine @@ -13,18 +16,18 @@ chkin_iec: lda LAT, Y cmp #$01 - beq_far chkin_file_not_input + beq_16 chkin_file_not_input // Send TALK + TKSA first lda FAT,Y jsr TALK - bcs_far chkinout_device_not_present + bcs_16 chkinout_device_not_present lda LAT, Y ora #$60 jsr TKSA - bcs_far chkinout_device_not_present + bcs_16 chkinout_device_not_present jmp chkin_set_device diff --git a/c64/kernal/iec/chrin_iec.s b/c64/kernal/iec/chrin_iec.s index 93ad7afc..2154cb5a 100644 --- a/c64/kernal/iec/chrin_iec.s +++ b/c64/kernal/iec/chrin_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the CHRIN routine diff --git a/c64/kernal/iec/chrout_iec.s b/c64/kernal/iec/chrout_iec.s index 38924b76..d8c41ab5 100644 --- a/c64/kernal/iec/chrout_iec.s +++ b/c64/kernal/iec/chrout_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the CHROUT routine @@ -8,5 +11,5 @@ chrout_iec: lda SCHAR jsr JCIOUT - bcc_far chrout_done_success + bcc_16 chrout_done_success jmp chrout_done_fail diff --git a/c64/kernal/iec/ciout.s b/c64/kernal/iec/ciout.s index 3b92cc14..6a35c029 100644 --- a/c64/kernal/iec/ciout.s +++ b/c64/kernal/iec/ciout.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 279/280 -// - [CM64] Compute's Mapping the Commodore 64 - page 224 +// - [RG64] C64 Programmers Reference Guide - page 279/280 +// - [CM64] Computes Mapping the Commodore 64 - page 224 // // CPU registers that has to be preserved (see [RG64]): .X, .Y // diff --git a/c64/kernal/iec/ckout_iec.s b/c64/kernal/iec/ckout_iec.s index 662f4840..dcbd4aa3 100644 --- a/c64/kernal/iec/ckout_iec.s +++ b/c64/kernal/iec/ckout_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the CKOUT routine @@ -12,18 +15,18 @@ ckout_iec: // Fail if the file is open for reading (secondary address 0) lda LAT, Y - beq_far ckout_file_not_output + beq_16 ckout_file_not_output // Send LISTEN + SECOND first lda FAT,Y jsr LISTEN - bcs_far chkinout_device_not_present + bcs_16 chkinout_device_not_present lda LAT, Y ora #$60 jsr SECOND - bcs_far chkinout_device_not_present + bcs_16 chkinout_device_not_present jmp ckout_set_device diff --git a/c64/kernal/iec/close_iec.s b/c64/kernal/iec/close_iec.s index 0cdc2801..d4ef88ac 100644 --- a/c64/kernal/iec/close_iec.s +++ b/c64/kernal/iec/close_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the CLOSE routine diff --git a/c64/kernal/iec/clrchn_iec.s b/c64/kernal/iec/clrchn_iec.s index 84993a0c..263f924f 100644 --- a/c64/kernal/iec/clrchn_iec.s +++ b/c64/kernal/iec/clrchn_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the CLRCHN routine @@ -22,7 +25,7 @@ clrchn_iec: jsr iec_check_devnum_oc // If it was IEC device - send UNLSN first - bcc_far UNLSN + bcc_16 UNLSN rts diff --git a/c64/kernal/iec/iec_check_devnum.s b/c64/kernal/iec/iec_check_devnum.s index e6ac9c08..8dd5de91 100644 --- a/c64/kernal/iec/iec_check_devnum.s +++ b/c64/kernal/iec/iec_check_devnum.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Checks whether device number (in .A) is a correct IEC device number diff --git a/c64/kernal/iec/iec_close_load.s b/c64/kernal/iec/iec_close_load.s index 5cc8e76a..4c088b8f 100644 --- a/c64/kernal/iec/iec_close_load.s +++ b/c64/kernal/iec/iec_close_load.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Common part of CLOSE and LOAD/SAVE routines for IEC diff --git a/c64/kernal/iec/iec_cmd_close.s b/c64/kernal/iec/iec_cmd_close.s index 126cb04e..095e2000 100644 --- a/c64/kernal/iec/iec_cmd_close.s +++ b/c64/kernal/iec/iec_cmd_close.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Kernal internal IEC routine diff --git a/c64/kernal/iec/iec_cmd_open.s b/c64/kernal/iec/iec_cmd_open.s index 54159d78..6d1bba33 100644 --- a/c64/kernal/iec/iec_cmd_open.s +++ b/c64/kernal/iec/iec_cmd_open.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Kernal internal IEC routine @@ -17,6 +20,12 @@ iec_cmd_open: // similar to TKSA, but without turnaround !: ora #$F0 +#if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT + pha + jsr burst_advertise + pla +#endif + #if CONFIG_IEC_DOLPHINDOS sta TBTCNT @@ -24,6 +33,7 @@ iec_cmd_open: // similar to TKSA, but without turnaround bcs !+ // branch if error jsr dolphindos_detect + jmp iec_tx_command_finalize #else diff --git a/c64/kernal/iec/iec_pull_release.s b/c64/kernal/iec/iec_pull_release.s index 8be0e851..d6fb93e0 100644 --- a/c64/kernal/iec/iec_pull_release.s +++ b/c64/kernal/iec/iec_pull_release.s @@ -1,85 +1,88 @@ - -// -// Helper IEC routines to pull/release certain lines -// -// Order of operation is set for extra robustness, on non-emulated hardware -// lines might need few cycles to stabilize (released CLK = DATA considered valid), -// see page 10 of http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf -// - - - -#if CONFIG_IEC - - -iec_pull_atn_clk_release_data: - - lda CIA2_PRA - ora #BIT_CIA2_PRA_ATN_OUT // pull - sta CIA2_PRA - - // FALLTROUGH - -iec_pull_clk_release_data: - - lda CIA2_PRA - ora #BIT_CIA2_PRA_CLK_OUT // pull - sta CIA2_PRA -!: - and #$FF - BIT_CIA2_PRA_DAT_OUT // release - bne iec_pull_release_end // branch always - -iec_pull_clk_release_data_oneshot: - - lda CIA2_PRA - ora #BIT_CIA2_PRA_CLK_OUT // pull - bne !- // branch always - -iec_release_atn_clk_data: - - lda CIA2_PRA - and #$FF - BIT_CIA2_PRA_ATN_OUT // release - sta CIA2_PRA - - // FALLTROUGH - -iec_release_clk_data: - - lda CIA2_PRA - and #$FF - BIT_CIA2_PRA_DAT_OUT // release - sta CIA2_PRA - and #$FF - BIT_CIA2_PRA_CLK_OUT // release - jmp iec_pull_release_end - -iec_release_clk_pull_data: - - lda CIA2_PRA - ora #BIT_CIA2_PRA_DAT_OUT // pull - sta CIA2_PRA - and #$FF - BIT_CIA2_PRA_CLK_OUT // release - bne iec_pull_release_end // branch always - -iec_pull_data_release_atn_clk: - - lda CIA2_PRA - ora #BIT_CIA2_PRA_DAT_OUT // pull - sta CIA2_PRA - and #$FF - BIT_CIA2_PRA_CLK_OUT // release - sta CIA2_PRA - - // FALLTROUGH - -iec_release_atn: - - lda CIA2_PRA - and #$FF - BIT_CIA2_PRA_ATN_OUT // release - - // FALLTROUGH - -iec_pull_release_end: - - sta CIA2_PRA - rts - - -#endif // CONFIG_IEC +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Helper IEC routines to pull/release certain lines +// +// Order of operation is set for extra robustness, on non-emulated hardware +// lines might need few cycles to stabilize (released CLK = DATA considered valid), +// see page 10 of http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf +// + + + +#if CONFIG_IEC + + +iec_pull_atn_clk_release_data: + + lda CIA2_PRA + ora #BIT_CIA2_PRA_ATN_OUT // pull + sta CIA2_PRA + + // FALLTROUGH + +iec_pull_clk_release_data: + + lda CIA2_PRA + ora #BIT_CIA2_PRA_CLK_OUT // pull + sta CIA2_PRA +!: + and #$FF - BIT_CIA2_PRA_DAT_OUT // release + bne iec_pull_release_end // branch always + +iec_pull_clk_release_data_oneshot: + + lda CIA2_PRA + ora #BIT_CIA2_PRA_CLK_OUT // pull + bne !- // branch always + +iec_release_atn_clk_data: + + lda CIA2_PRA + and #$FF - BIT_CIA2_PRA_ATN_OUT // release + sta CIA2_PRA + + // FALLTROUGH + +iec_release_clk_data: + + lda CIA2_PRA + and #$FF - BIT_CIA2_PRA_DAT_OUT // release + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT // release + jmp iec_pull_release_end + +iec_release_clk_pull_data: + + lda CIA2_PRA + ora #BIT_CIA2_PRA_DAT_OUT // pull + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT // release + bne iec_pull_release_end // branch always + +iec_pull_data_release_atn_clk: + + lda CIA2_PRA + ora #BIT_CIA2_PRA_DAT_OUT // pull + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT // release + sta CIA2_PRA + + // FALLTROUGH + +iec_release_atn: + + lda CIA2_PRA + and #$FF - BIT_CIA2_PRA_ATN_OUT // release + + // FALLTROUGH + +iec_pull_release_end: + + sta CIA2_PRA + rts + + +#endif // CONFIG_IEC diff --git a/c64/kernal/iec/iec_return.s b/c64/kernal/iec/iec_return.s index b73a8d1f..0c0377a4 100644 --- a/c64/kernal/iec/iec_return.s +++ b/c64/kernal/iec/iec_return.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routines to return with error/success diff --git a/c64/kernal/iec/iec_rx_byte.s b/c64/kernal/iec/iec_rx_byte.s index 56d54aa6..9dd110df 100644 --- a/c64/kernal/iec/iec_rx_byte.s +++ b/c64/kernal/iec/iec_rx_byte.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Receive a byte from the IEC bus. // Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc, // http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf (page 11) @@ -14,7 +18,7 @@ iec_rx_dispatch: lda IECPROTO cmp #$01 - beq_far jiffydos_rx_byte + beq_16 jiffydos_rx_byte // FALLTROUGH diff --git a/c64/kernal/iec/iec_rx_check_eoi.s b/c64/kernal/iec/iec_rx_check_eoi.s index b36d840e..26de252e 100644 --- a/c64/kernal/iec/iec_rx_check_eoi.s +++ b/c64/kernal/iec/iec_rx_check_eoi.s @@ -1,8 +1,14 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routine to check for EOI while receiving byte from IEC // +#if CONFIG_IEC + + iec_rx_check_eoi: // Wait for talker to pull CLK. @@ -33,3 +39,6 @@ iec_rx_check_eoi_confirm: iec_rx_check_eoi_done: rts + + +#endif // CONFIG_IEC diff --git a/c64/kernal/iec/iec_send_file_name.s b/c64/kernal/iec/iec_send_file_name.s index 72f107bf..b250612a 100644 --- a/c64/kernal/iec/iec_send_file_name.s +++ b/c64/kernal/iec/iec_send_file_name.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Sends file (stream) name to IEC device diff --git a/c64/kernal/iec/iec_set_idle.s b/c64/kernal/iec/iec_set_idle.s index 4833eba6..a6f135c8 100644 --- a/c64/kernal/iec/iec_set_idle.s +++ b/c64/kernal/iec/iec_set_idle.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE #if CONFIG_IEC diff --git a/c64/kernal/iec/iec_turnaround_to_listen.s b/c64/kernal/iec/iec_turnaround_to_listen.s index f77a5a54..9dbd9bf4 100644 --- a/c64/kernal/iec/iec_turnaround_to_listen.s +++ b/c64/kernal/iec/iec_turnaround_to_listen.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // According to http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // pages 7--8. // See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc diff --git a/c64/kernal/iec/iec_turnaround_to_talk.s b/c64/kernal/iec/iec_turnaround_to_talk.s index 624c648d..2c5032a8 100644 --- a/c64/kernal/iec/iec_turnaround_to_talk.s +++ b/c64/kernal/iec/iec_turnaround_to_talk.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // According to http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // pages 7--8. // See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc diff --git a/c64/kernal/iec/iec_tx_byte.s b/c64/kernal/iec/iec_tx_byte.s index 91b91abb..53295b0a 100644 --- a/c64/kernal/iec/iec_tx_byte.s +++ b/c64/kernal/iec/iec_tx_byte.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc diff --git a/c64/kernal/iec/iec_tx_command.s b/c64/kernal/iec/iec_tx_command.s index 04c8a0ca..68d2b8f7 100644 --- a/c64/kernal/iec/iec_tx_command.s +++ b/c64/kernal/iec/iec_tx_command.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc diff --git a/c64/kernal/iec/iec_tx_command_finalize.s b/c64/kernal/iec/iec_tx_command_finalize.s index 976fdb93..22b3594c 100644 --- a/c64/kernal/iec/iec_tx_command_finalize.s +++ b/c64/kernal/iec/iec_tx_command_finalize.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // Routine to finalize some IEC commands - which do not end in turnaround and are not followed by others // Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc diff --git a/c64/kernal/iec/iec_tx_flush.s b/c64/kernal/iec/iec_tx_flush.s index fdef1d2a..f2c7141b 100644 --- a/c64/kernal/iec/iec_tx_flush.s +++ b/c64/kernal/iec/iec_tx_flush.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // Flush the IEC output buffer (if not empty) - send byte with EOI // diff --git a/c64/kernal/iec_fast/iec_fast_common.s b/c64/kernal/iec/iec_update_eal_by_y.s similarity index 63% rename from c64/kernal/iec_fast/iec_fast_common.s rename to c64/kernal/iec/iec_update_eal_by_y.s index a7ce0bb6..88187449 100644 --- a/c64/kernal/iec_fast/iec_fast_common.s +++ b/c64/kernal/iec/iec_update_eal_by_y.s @@ -1,6 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // -// Common routines for multiple IEC fact protocols +// Common EAL update routine // diff --git a/c64/kernal/iec/iec_wait1ms.s b/c64/kernal/iec/iec_wait1ms.s index 9e550f35..2b1452fd 100644 --- a/c64/kernal/iec/iec_wait1ms.s +++ b/c64/kernal/iec/iec_wait1ms.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Wait 1 ms (1000 usec) // // On NTSC this means 1023 cycles (slightly less on PAL, but we have to be sure). -// We can't count on badlines, as the screen might be disabled. +// We cant count on badlines, as the screen might be disabled. // Delay here is implemented using VIC-II raster register. Since one raster is // 63 cycles, we need at least 17 full rasters to be 100% sure we wait enough @@ -16,9 +19,8 @@ iec_wait1ms: ldx #18 // we probably won't start with the beginning of raster #endif // CONFIG_IEC -#if CONFIG_IEC || CONFIG_TAPE_TURBO || CONFIG_TAPE_NORMAL -wait_x_bars: // additional entry point for tape support +wait_x_bars: // additional entry point for delayy in screen and tape support // has to preserve .Y and put .X to 0 lda VIC_RASTER @@ -32,6 +34,3 @@ wait_x_bars: // additional entry point for tape support iec_wait_rts: // dummy RTS, for very short waits rts - - -#endif // CONFIG_IEC || CONFIG_TAPE_TURBO || CONFIG_TAPE_NORMAL diff --git a/c64/kernal/iec/iec_wait20us.s b/c64/kernal/iec/iec_wait20us.s index 21c5caa5..d5db90ed 100644 --- a/c64/kernal/iec/iec_wait20us.s +++ b/c64/kernal/iec/iec_wait20us.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE #if CONFIG_IEC diff --git a/c64/kernal/iec/iec_wait60us.s b/c64/kernal/iec/iec_wait60us.s index 5673d528..6b83e45f 100644 --- a/c64/kernal/iec/iec_wait60us.s +++ b/c64/kernal/iec/iec_wait60us.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Note: damages .X diff --git a/c64/kernal/iec/iec_wait_for_clk_release.s b/c64/kernal/iec/iec_wait_for_clk_release.s index 25a65bd8..ac259952 100644 --- a/c64/kernal/iec/iec_wait_for_clk_release.s +++ b/c64/kernal/iec/iec_wait_for_clk_release.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE #if CONFIG_IEC diff --git a/c64/kernal/iec/iec_wait_for_data_pull.s b/c64/kernal/iec/iec_wait_for_data_pull.s index e4842c61..d74a5675 100644 --- a/c64/kernal/iec/iec_wait_for_data_pull.s +++ b/c64/kernal/iec/iec_wait_for_data_pull.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE #if CONFIG_IEC diff --git a/c64/kernal/iec/iec_wait_for_data_release.s b/c64/kernal/iec/iec_wait_for_data_release.s index e75c2ef2..d4f483b4 100644 --- a/c64/kernal/iec/iec_wait_for_data_release.s +++ b/c64/kernal/iec/iec_wait_for_data_release.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE #if CONFIG_IEC diff --git a/c64/kernal/iec/listen.s b/c64/kernal/iec/listen.s index f7e59c8c..33bb554d 100644 --- a/c64/kernal/iec/listen.s +++ b/c64/kernal/iec/listen.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 285 -// - [CM64] Compute's Mapping the Commodore 64 - page 223 +// - [RG64] C64 Programmers Reference Guide - page 285 +// - [CM64] Computes Mapping the Commodore 64 - page 223 // - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc // - http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // diff --git a/c64/kernal/iec/load_iec.s b/c64/kernal/iec/load_iec.s index d901e6a7..578e9f97 100644 --- a/c64/kernal/iec/load_iec.s +++ b/c64/kernal/iec/load_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the LOAD routine @@ -29,7 +32,7 @@ load_iec: // Check file name lda FNLEN - beq_far kernalerror_FILE_NAME_MISSING + beq_16 kernalerror_FILE_NAME_MISSING // Display SEARCHING FOR + filename jsr lvs_display_searching_for @@ -57,15 +60,17 @@ load_iec: jsr TALK bcs load_iec_error +#if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT + jsr burst_advertise +#endif + lda #$60 // open channel / data (p3) , required according to p13 sta TBTCNT jsr iec_tx_command bcs load_iec_error #if CONFIG_IEC_DOLPHINDOS - jsr dolphindos_detect - #endif // We are currently talker, so do the IEC turn around so that we @@ -103,12 +108,12 @@ load_iec: #if CONFIG_IEC_JIFFYDOS cmp #$01 - beq_far jiffydos_load // branch if JiffyDOS + beq_16 jiffydos_load // branch if JiffyDOS #endif #if CONFIG_IEC_DOLPHINDOS cmp #$02 - beq_far dolphindos_load // branch if DolphinDOS + beq_16 dolphindos_load // branch if DolphinDOS #endif #endif @@ -146,7 +151,7 @@ load_iec_loop: phx_trash_a jsr udtim_keyboard jsr STOP - bcs_far load_break_error + bcs_16 load_break_error plx_trash_a !: // Check for EOI - if so, this was the last byte diff --git a/c64/kernal/iec/open_iec.s b/c64/kernal/iec/open_iec.s index a4ff090e..a2ed2354 100644 --- a/c64/kernal/iec/open_iec.s +++ b/c64/kernal/iec/open_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the OPEN routine diff --git a/c64/kernal/iec/save_iec.s b/c64/kernal/iec/save_iec.s index bd6aade5..a90827a7 100644 --- a/c64/kernal/iec/save_iec.s +++ b/c64/kernal/iec/save_iec.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // IEC part of the SAVE routine @@ -15,7 +18,7 @@ save_iec: // Check file name lda FNLEN - beq_far kernalerror_FILE_NAME_MISSING + beq_16 kernalerror_FILE_NAME_MISSING // Display SAVING jsr lvs_display_saving @@ -39,15 +42,17 @@ save_iec: jsr LISTEN bcs save_iec_dev_not_found +#if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT + jsr burst_advertise +#endif + lda #$61 // open channel / data (p3) , required according to p13 sta TBTCNT jsr iec_tx_command bcs save_iec_dev_not_found #if CONFIG_IEC_DOLPHINDOS - jsr dolphindos_detect - #endif // Save start address @@ -122,4 +127,4 @@ iec_save_loop_end: rts -#endif // CONFIG_IEC \ No newline at end of file +#endif // CONFIG_IEC diff --git a/c64/kernal/iec/second.s b/c64/kernal/iec/second.s index d1931234..60fce725 100644 --- a/c64/kernal/iec/second.s +++ b/c64/kernal/iec/second.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 296 -// - [CM64] Compute's Mapping the Commodore 64 - page 223/224 +// - [RG64] C64 Programmers Reference Guide - page 296 +// - [CM64] Computes Mapping the Commodore 64 - page 223/224 // - https://www.pagetable.com/?p=1031, , https://github.com/mist64/cbmbus_doc // // CPU registers that has to be preserved (see [RG64]): .X, .Y diff --git a/c64/kernal/iec/talk.s b/c64/kernal/iec/talk.s index f9726d4d..23b0504e 100644 --- a/c64/kernal/iec/talk.s +++ b/c64/kernal/iec/talk.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 301/302 -// - [CM64] Compute's Mapping the Commodore 64 - page 223 +// - [RG64] C64 Programmers Reference Guide - page 301/302 +// - [CM64] Computes Mapping the Commodore 64 - page 223 // - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc // - http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // diff --git a/c64/kernal/iec/tksa.s b/c64/kernal/iec/tksa.s index 9794a7b9..59d0b9e5 100644 --- a/c64/kernal/iec/tksa.s +++ b/c64/kernal/iec/tksa.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 302 -// - [CM64] Compute's Mapping the Commodore 64 - page 224 +// - [RG64] C64 Programmers Reference Guide - page 302 +// - [CM64] Computes Mapping the Commodore 64 - page 224 // - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc // // CPU registers that has to be preserved (see [RG64]): .X, .Y diff --git a/c64/kernal/iec/unlsn.s b/c64/kernal/iec/unlsn.s index 857956c6..d727fd92 100644 --- a/c64/kernal/iec/unlsn.s +++ b/c64/kernal/iec/unlsn.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 303 -// - [CM64] Compute's Mapping the Commodore 64 - page 224 +// - [RG64] C64 Programmers Reference Guide - page 303 +// - [CM64] Computes Mapping the Commodore 64 - page 224 // - https://www.pagetable.com/?p=1031, , https://github.com/mist64/cbmbus_doc // - http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // diff --git a/c64/kernal/iec/untlk.s b/c64/kernal/iec/untlk.s index e4bb2717..2fab716a 100644 --- a/c64/kernal/iec/untlk.s +++ b/c64/kernal/iec/untlk.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 304 -// - [CM64] Compute's Mapping the Commodore 64 - page 224 +// - [RG64] C64 Programmers Reference Guide - page 304 +// - [CM64] Computes Mapping the Commodore 64 - page 224 // - https://www.pagetable.com/?p=1031, , https://github.com/mist64/cbmbus_doc // - http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // @@ -33,7 +36,7 @@ common_untlk_tksa: // common part of UNTLK and TKSA sta TBTCNT jsr iec_tx_command bcs !+ // branch if error - // XXX - for TKSA, is it really the right place to do a turnaround? I've got some doubts + // XXX - for TKSA, is it really the right place to do a turnaround? I have some doubts // (it forces us to send the TKSA command 'manually' sometimes), but // Luigi Di Fraia (https://luigidifraia.wordpress.com/2017/06/27/codebase64-on-the-kernal-behaviour/) // claims TKSA Kernal routine actually does the turnaround diff --git a/c64/kernal/iec_fast/burst_cia1_advertise.s b/c64/kernal/iec_fast/burst_cia1_advertise.s new file mode 100644 index 00000000..eb7e6e2b --- /dev/null +++ b/c64/kernal/iec_fast/burst_cia1_advertise.s @@ -0,0 +1,36 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Advertise burst IEC protocol support to the receiver +// + +// +// Based on idea by Pasi 'Albert' Ojala and description from +// https://sites.google.com/site/h2obsession/CBM/C128/fast-serial-for-uiec +// + + +#if CONFIG_IEC_BURST_CIA1 + + +burst_advertise: + +#if CONFIG_IEC_JIFFYDOS + + // Skip if other protocol (only JiffyDOS is possible at this moment) already detected + lda IECPROTO + bmi !+ + bne burst_advertise_done +!: +#endif + + panic #$FF // XXX implement this + +burst_advertise_done: + + rts + + +#endif diff --git a/c64/kernal/iec_fast/burst_cia2_advertise.s b/c64/kernal/iec_fast/burst_cia2_advertise.s new file mode 100644 index 00000000..26303cc5 --- /dev/null +++ b/c64/kernal/iec_fast/burst_cia2_advertise.s @@ -0,0 +1,60 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Advertise burst IEC protocol support to the receiver +// + +// +// Based on idea by Pasi 'Albert' Ojala and description from +// https://sites.google.com/site/h2obsession/CBM/C128/fast-serial-for-uiec +// + + +#if CONFIG_IEC_BURST_CIA2 + + +burst_advertise: + +#if CONFIG_IEC_JIFFYDOS + + // Skip if other protocol (only JiffyDOS is possible at this moment) already detected + lda IECPROTO + bmi !+ + bne burst_advertise_done +!: +#endif + + // Make sure this is not done under ATN + jst iec_release_atn + + // Set the clock rate to the fastest possible + ldy #$01 + sty CIA2_TIMALO + dey + sty CIA2_TIMAHI + + // Prepare registers for transfer + lda #$C1 + sta CIA2_CRA // start timer A, serial out, TOD 50Hz + bit CIA2_ICR // clear interrupt register + + // Send test byte + lda #$FF // $FF keeps DATA released, see https://www.c64-wiki.com/wiki/Fast_serial_bus_protocol + sta CIA2_SDR + + // Wait until byte sent + lda #$08 // interrupt mask +!: + bit CIA2_ICR + beq !- + + // FALLTROUGH + +burst_advertise_done: + + rts + + +#endif diff --git a/c64/kernal/iec_fast/burst_soft_advertise.s b/c64/kernal/iec_fast/burst_soft_advertise.s new file mode 100644 index 00000000..7e9e9dcf --- /dev/null +++ b/c64/kernal/iec_fast/burst_soft_advertise.s @@ -0,0 +1,31 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Advertise burst IEC protocol support to the receiver +// + + +#if CONFIG_IEC_BURST_SOFT + + +burst_advertise: + +#if CONFIG_IEC_JIFFYDOS + + // Skip if other protocol (only JiffyDOS is possible at this moment) already detected + lda IECPROTO + bmi !+ + bne burst_advertise_done: +!: +#endif + + panic #$FF // XXX implement this + +burst_advertise_done: + + rts + + +#endif diff --git a/c64/kernal/iec_fast/dolphindos_detect.s b/c64/kernal/iec_fast/dolphindos_detect.s index 3f622482..92a53649 100644 --- a/c64/kernal/iec_fast/dolphindos_detect.s +++ b/c64/kernal/iec_fast/dolphindos_detect.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routine for JiffyDOS detection @@ -20,13 +23,6 @@ dolphindos_detect: -#if CONFIG_IEC_JIFFYDOS - - lda IECPROTO - bne dolphindos_detect_fail // skip if other protocol already detected - -#endif - // Make sure the port settings are correct lda #$7F diff --git a/c64/kernal/iec_fast/dolphindos_load.s b/c64/kernal/iec_fast/dolphindos_load.s index 849f3948..f32a8502 100644 --- a/c64/kernal/iec_fast/dolphindos_load.s +++ b/c64/kernal/iec_fast/dolphindos_load.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // DolphinDOS protocol support for IEC - optimized load loop diff --git a/c64/kernal/iec_fast/jiffydos_bittable.s b/c64/kernal/iec_fast/jiffydos_bittable.s index 94e89a39..0ac8081e 100644 --- a/c64/kernal/iec_fast/jiffydos_bittable.s +++ b/c64/kernal/iec_fast/jiffydos_bittable.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper table for encoding lower nibble for JiffyDOS, diff --git a/c64/kernal/iec_fast/jiffydos_detect.s b/c64/kernal/iec_fast/jiffydos_detect.s index 0058ad87..3488ee6b 100644 --- a/c64/kernal/iec_fast/jiffydos_detect.s +++ b/c64/kernal/iec_fast/jiffydos_detect.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routine for JiffyDOS detection diff --git a/c64/kernal/iec_fast/jiffydos_load.s b/c64/kernal/iec_fast/jiffydos_load.s index 5b6ca0c4..0fc3a11b 100644 --- a/c64/kernal/iec_fast/jiffydos_load.s +++ b/c64/kernal/iec_fast/jiffydos_load.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // JiffyDOS protocol support for IEC - optimized load loop @@ -20,7 +23,7 @@ jiffydos_load: // Timing is critical, do not allow interrupts sei -#if CONFIG_IEC_BLANK_SCREEN +#if CONFIG_IEC_JIFFYDOS_BLANK // Preserve register with screen status (blank/visibe) lda VIC_SCROLY @@ -57,7 +60,7 @@ jiffydos_load_loop: lda CIA2_PRA and #$FF - BIT_CIA2_PRA_DAT_OUT // release -#if CONFIG_IEC_BLANK_SCREEN +#if CONFIG_IEC_JIFFYDOS_BLANK // It seems JiffyDOS needs some time here; waste few cycles nop @@ -143,7 +146,7 @@ jiffydos_load_end: lda #$01 sta IECPROTO -#if CONFIG_IEC_BLANK_SCREEN +#if CONFIG_IEC_JIFFYDOS_BLANK // Restore screen state lda TBTCNT diff --git a/c64/kernal/iec_fast/jiffydos_prepare.s b/c64/kernal/iec_fast/jiffydos_prepare.s index 1dc8f29b..214248af 100644 --- a/c64/kernal/iec_fast/jiffydos_prepare.s +++ b/c64/kernal/iec_fast/jiffydos_prepare.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // JiffyDOS transfer preparation routine diff --git a/c64/kernal/iec_fast/jiffydos_rx_byte.s b/c64/kernal/iec_fast/jiffydos_rx_byte.s index cb55f3ec..13406df8 100644 --- a/c64/kernal/iec_fast/jiffydos_rx_byte.s +++ b/c64/kernal/iec_fast/jiffydos_rx_byte.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // JiffyDOS protocol support for IEC - byte reception diff --git a/c64/kernal/iec_fast/jiffydos_tx_byte.s b/c64/kernal/iec_fast/jiffydos_tx_byte.s index 26be0860..d600cc3f 100644 --- a/c64/kernal/iec_fast/jiffydos_tx_byte.s +++ b/c64/kernal/iec_fast/jiffydos_tx_byte.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // JiffyDOS protocol support for IEC - byte transfer diff --git a/c64/kernal/iec_fast/jiffydos_wait_line.s b/c64/kernal/iec_fast/jiffydos_wait_line.s index cf6e9169..171b3f18 100644 --- a/c64/kernal/iec_fast/jiffydos_wait_line.s +++ b/c64/kernal/iec_fast/jiffydos_wait_line.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // JiffyDOS helper routine to wait for appropriate moment, diff --git a/c64/kernal/init/cartridge_check.s b/c64/kernal/init/cartridge_check.s index 00221fb4..b47c61e7 100644 --- a/c64/kernal/init/cartridge_check.s +++ b/c64/kernal/init/cartridge_check.s @@ -1,13 +1,22 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // c64 prg p263 cartridge_check: + ldx #$05 -cartridge_check_l1: +!: lda CART_SIG-1,x cmp cartridge_signature-1,x - bne no_cartridge + bne cartridge_check_end dex - bne cartridge_check_l1 + bne !- + // FALLTROUGH -no_cartridge: + +cartridge_check_end: + rts diff --git a/c64/kernal/init/cint_screen_keyboard.s b/c64/kernal/init/cint_screen_keyboard.s index 0470d710..ad2241c3 100644 --- a/c64/kernal/init/cint_screen_keyboard.s +++ b/c64/kernal/init/cint_screen_keyboard.s @@ -1,10 +1,15 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // This is a part CINT which initializes screen and keyboard // // For more details see: -// - [RG64] C64 Programmer's Reference Guide - page 280 -// - [CM64] Compute's Mapping the Commodore 64 - page 242 +// - [RG64] C64 Programmers Reference Guide - page 280 +// - [CM64] Computes Mapping the Commodore 64 - page 242 +// + cint_screen_keyboard: @@ -15,7 +20,7 @@ cint_screen_keyboard: lda #>scnkey_set_keytab sta KEYLOG+1 - // Initialise cursor blink flags (Compute's Mapping the 64 p215) + // Initialise cursor blink flags (Computes Mapping the 64 p215) lda #$01 sta BLNCT @@ -30,7 +35,7 @@ cint_screen_keyboard: #endif - // Set keyboard decode vector (Compute's Mapping the 64 p215) + // Set keyboard decode vector (Computes Mapping the 64 p215) #if CONFIG_LEGACY_SCNKEY @@ -42,10 +47,10 @@ cint_screen_keyboard: bpl !- sta BufferQuantity - // Set key repeat delay (Compute's Mapping the 64 p215) + // Set key repeat delay (Computes Mapping the 64 p215) // Making some numbers up here: Repeat every ~1/10th sec // But require key to be held for ~1/3sec before - // repeating (Compute's Mapping the 64 p58) + // repeating (Computes Mapping the 64 p58) // Not needed for default keyboard scanning code @@ -54,11 +59,11 @@ cint_screen_keyboard: #endif - // Set current colour for text (Compute's Mapping the 64 p215) + // Set current colour for text (Computes Mapping the 64 p215) ldx #$01 // default is light blue ($0E), but we use a different one stx COLOR - // Set maximum keyboard buffer size (Compute's Mapping the 64 p215) + // Set maximum keyboard buffer size (Computes Mapping the 64 p215) ldx #10 stx XMAX @@ -66,6 +71,6 @@ cint_screen_keyboard: ldx #$00 stx MODE - // Fallthrough/jump to screen clear routine (Compute's Mapping the 64 p215) + // Fallthrough/jump to screen clear routine (Computes Mapping the 64 p215) jmp clear_screen diff --git a/c64/kernal/init/e518.cint_legacy.s b/c64/kernal/init/e518.cint_legacy.s index 93effe63..a143692d 100644 --- a/c64/kernal/init/e518.cint_legacy.s +++ b/c64/kernal/init/e518.cint_legacy.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Part of the official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 280 -// - [CM64] Compute's Mapping the Commodore 64 - page 242 +// - [RG64] C64 Programmers Reference Guide - page 280 +// - [CM64] Computes Mapping the Commodore 64 - page 242 // // CPU registers that has to be preserved (see [RG64]): none // diff --git a/c64/kernal/init/e5a0.setup_vicii.s b/c64/kernal/init/e5a0.setup_vicii.s index 78ab30a9..a7a3e4f4 100644 --- a/c64/kernal/init/e5a0.setup_vicii.s +++ b/c64/kernal/init/e5a0.setup_vicii.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Well-known Kernal routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - page 215 +// - [CM64] Computes Mapping the Commodore 64 - page 215 // @@ -20,7 +23,7 @@ setup_vicii: #if !CONFIG_MB_MEGA_65 && !CONFIG_MB_ULTIMATE_64 - // Disable C128 extra keys - just to be sure they won't interfere with anything + // Disable C128 extra keys - just to be sure they will not interfere with anything stx VIC_XSCAN diff --git a/c64/kernal/init/fce2.hw_entry_reset.s b/c64/kernal/init/fce2.hw_entry_reset.s index 29348a67..dbe2c942 100644 --- a/c64/kernal/init/fce2.hw_entry_reset.s +++ b/c64/kernal/init/fce2.hw_entry_reset.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Resources describing the C64 reset sequence: // https://www.c64-wiki.com/wiki/Reset_(Process) diff --git a/c64/kernal/init/fd50.ramtas.s b/c64/kernal/init/fd50.ramtas.s index 70cb41c7..cb135a4a 100644 --- a/c64/kernal/init/fd50.ramtas.s +++ b/c64/kernal/init/fd50.ramtas.s @@ -1,18 +1,30 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 KERNAL_0 #TAKE +// #LAYOUT# M65 KERNAL_1 #TAKE-FLOAT +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 291 -// - [CM64] Compute's Mapping the Commodore 64 - page 237 +// - [RG64] C64 Programmers Reference Guide - page 291 +// - [CM64] Computes Mapping the Commodore 64 - page 237 // // CPU registers that has to be preserved (see [RG64]): none // RAMTAS: - // C64 Programmer's Reference guide p291: +#if (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) + + jsr map_KERNAL_1 + jsr KERNAL_1__RAMTAS + jmp map_NORMAL + +#else + + // C64 Programmers Reference guide p291: // Clear $0000-$0101, $0200-$03ff - // PGS: $0000, $0001 are CPU IO ports, so shouldn't get written to + // PGS: $0000, $0001 are CPU IO ports, so should not get written to // How many ways are there to efficiently erase these two pages // of RAM? We would like to avoid any unnecessary byte similarity @@ -26,7 +38,7 @@ RAMTAS: !: sta $0300,Y sta $0200,Y - sta $0002,Y // that's why we don't use .X for index, we do not want zeropage addressing here! + sta $0002,Y // that is why we do not use .X for index, we do not want zeropage addressing here! iny bne !- @@ -81,3 +93,5 @@ ramtas_32k: ldy #$80 bne !- // branch always + +#endif // ROM layout diff --git a/c64/kernal/init/fda3.ioinit.s b/c64/kernal/init/fda3.ioinit.s index 59fa824d..e0fa1ecd 100644 --- a/c64/kernal/init/fda3.ioinit.s +++ b/c64/kernal/init/fda3.ioinit.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 285 -// - [CM64] Compute's Mapping the Commodore 64 - page 238 +// - [RG64] C64 Programmers Reference Guide - page 285 +// - [CM64] Computes Mapping the Commodore 64 - page 238 // // CPU registers that has to be preserved (see [RG64]): none // @@ -22,8 +25,8 @@ IOINIT: ldx #$27 stx CPU_R6510 - ldx #$EF - stx CPU_D6510 // [CM64] page 4 + ldx #$2F // checked real ROM value + stx CPU_D6510 // // Now prevent the CIAs from generating interrupts, who knows what damage they can do @@ -110,12 +113,11 @@ IOINIT: lda #$3F sta CIA2_DDRA // $DD02 - // XXX detect TOD clock, see https://codebase64.org/doku.php?id=base:efficient_tod_initialisation - - // XXX how to initialize these timers??? - // stx CIA1_CRB // $DC0F - // stx CIA2_CRA // $DD0E - // stx CIA2_CRB // $DD0F + // Checked using VICE that original ROM initializes timers this way + ldx #$08 + stx CIA1_CRB // $DC0F + stx CIA2_CRA // $DD0E + stx CIA2_CRB // $DD0F // Set VIC-II bank - at least the 'Operacja Proboszcz' game needs this within IOINIT // Checked on original ROMs, that it sets bit #2 (RS-232 output) high @@ -123,13 +125,8 @@ IOINIT: ldx #%00000111 // XXX adapt this to IEC idle state, JMP at the end won't be needed stx CIA2_PRA // $DD00 - // - - ldy #<16421 - ldx #>16421 - - sty CIA1_TIMALO // $DC04 - stx CIA1_TIMAHI // $DC05 + // Put something sane in the IRQ timer + jsr setup_irq_timer // Enable timer A to run continuously (http://codebase64.org/doku.php?id=base:timerinterrupts) ldx #$11 diff --git a/c64/kernal/init/ff5b.cint.s b/c64/kernal/init/ff5b.cint.s index 6f8fe591..784bb73f 100644 --- a/c64/kernal/init/ff5b.cint.s +++ b/c64/kernal/init/ff5b.cint.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 280 -// - [CM64] Compute's Mapping the Commodore 64 - page 242 +// - [RG64] C64 Programmers Reference Guide - page 280 +// - [CM64] Computes Mapping the Commodore 64 - page 242 // // CPU registers that has to be preserved (see [RG64]): none // diff --git a/c64/kernal/init/fffc.vector_reset.s b/c64/kernal/init/fffc.vector_reset.s index 20545b6c..c8322445 100644 --- a/c64/kernal/init/fffc.vector_reset.s +++ b/c64/kernal/init/fffc.vector_reset.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // $FFFC - CPU Reset Vector // Uncontrovertial, as it is a CPU requirement, and nothing else. diff --git a/c64/kernal/init/setup_pal_ntsc.s b/c64/kernal/init/setup_pal_ntsc.s index 99668527..ebc22052 100644 --- a/c64/kernal/init/setup_pal_ntsc.s +++ b/c64/kernal/init/setup_pal_ntsc.s @@ -1,5 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE -// Detect video system (PAL/NTSC), use Graham's method, as it's short and reliable +// Detect video system (PAL/NTSC), use method by Graham, as it is short and reliable // see here: https://codebase64.org/doku.php?id=base:detect_pal_ntsc @@ -23,43 +26,39 @@ setup_pal_ntsc: setup_pal: - // Set timer interval to ~1/60th of a second - - // (This value was calculated by running a custom IRQ handler on a C64 - // with original KERNAL, and writing the values of $DC04/5 to the screen - // in the IRQ handler to see roughly what value the timers must be set to) - // ldy #<16380 - // ldx #>16380 - - // PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), - // is clocked at 0.985248 MHz, so that 1/60s is 16421 ($4025) CPU cycles - - ldy #<16421 - ldx #>16421 - lda #$01 + skip_2_bytes_trash_nvz + + // FALLTROUGH + +setup_ntsc: + + lda #$00 // FALLTROUGH setup_pal_ntsc_end: - sty CIA1_TIMALO // $DC04 - stx CIA1_TIMAHI // $DC05 - sta TVSFLG + // FALLTROUGH + +setup_irq_timer: // entry point needed by UP9600 and CIA1 burst mod support + + // Sets up IRQ timer in CIA1 to ~1/60th of a second, + // depending on the detected video system + + // Retrieve video system (0 - NTSC, 1 - PAL), assume PAL for unknown values + + ldx TVSFLG + beq !+ + ldx #$01 +!: + // Setup interval for timer A in CIA1 + + lda irq_timing_lo, x + sta CIA1_TIMALO // $DC04 + lda irq_timing_hi, x + sta CIA1_TIMAHI // $DC05 + rts - -setup_ntsc: - - // Set timer interval to ~1/60th of a second - - // NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), - // is clocked at 1.022727 MHz, so that 1/60s is 17045 ($4295) CPU cycles - - ldy #<17045 - ldx #>17045 - - lda #$00 - - beq setup_pal_ntsc_end // branch always diff --git a/c64/kernal/interrupts/ea31.default_irq_handler.s b/c64/kernal/interrupts/ea31.default_irq_handler.s index be964c9f..671839a3 100644 --- a/c64/kernal/interrupts/ea31.default_irq_handler.s +++ b/c64/kernal/interrupts/ea31.default_irq_handler.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + default_irq_handler: diff --git a/c64/kernal/interrupts/ea7e.ack_cia1_return_from_interrupt.s b/c64/kernal/interrupts/ea7e.ack_cia1_return_from_interrupt.s index ba5ebfa1..6ba7c968 100644 --- a/c64/kernal/interrupts/ea7e.ack_cia1_return_from_interrupt.s +++ b/c64/kernal/interrupts/ea7e.ack_cia1_return_from_interrupt.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // https://csdb.dk/forums/index.php?roomid=11&topicid=5776 // Clear the CIA1 interrupt flag, and then fall through to // the return from interrupt routine diff --git a/c64/kernal/interrupts/ea81.return_from_interrupt.s b/c64/kernal/interrupts/ea81.return_from_interrupt.s index 4d22d7ea..4a834206 100644 --- a/c64/kernal/interrupts/ea81.return_from_interrupt.s +++ b/c64/kernal/interrupts/ea81.return_from_interrupt.s @@ -1,8 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // The IRQ is a commonly messed with thing on the C64, // so we need to handle entry points that are commonly // relied upon, including: // $EA31 - Standard IRQ routine -// $EA61 - Check keyboard, but don't update timer? https://github.com/cc65/cc65/issues/324 +// $EA61 - Check keyboard, but do not update timer? https://github.com/cc65/cc65/issues/324 // $EA81 - https://www.lemon64.com/forum/viewtopic.php?t=2112&sid=6ea01982b26da69783120a7923ca46fb // Also the $0314 vector is widely used (e.g., https://www.lemon64.com/forum/viewtopic.php?t=2112&sid=6ea01982b26da69783120a7923ca46fb) @@ -10,9 +14,10 @@ return_from_interrupt: // Restore registers and return - // Sequence according to Compute's Mapping the 64 p73 + // Sequence according to Computes Mapping the 64 p73 ply_trash_a plx_trash_a pla + rti diff --git a/c64/kernal/interrupts/fe47.default_nmi_handler.s b/c64/kernal/interrupts/fe47.default_nmi_handler.s index 9f877bb5..96a2bccb 100644 --- a/c64/kernal/interrupts/fe47.default_nmi_handler.s +++ b/c64/kernal/interrupts/fe47.default_nmi_handler.s @@ -1,10 +1,14 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + default_nmi_handler: - // Implemented according to Compute's Mapping the Commodore 64, page 74 + // Implemented according to Computes Mapping the Commodore 64, page 74 // and to https://www.c64-wiki.com/wiki/Interrupt - // Save registers, sequence according to Compute's Mapping the Commodore 64, page 73 + // Save registers, sequence according to Computes Mapping the Commodore 64, page 73 pha phx_trash_a phy_trash_a @@ -25,7 +29,7 @@ default_nmi_handler: bcs !+ jmp return_from_interrupt // no STOP pressed !: - // STOP + RESTORE - clean the address of the BRK instruction (it's not BRK) first + // STOP + RESTORE - clean the address of the BRK instruction (it is not BRK) first lda #$00 sta CMP0+0 sta CMP0+1 diff --git a/c64/kernal/interrupts/fe66.default_brk_handler.s b/c64/kernal/interrupts/fe66.default_brk_handler.s index 78a63c72..bcec92a5 100644 --- a/c64/kernal/interrupts/fe66.default_brk_handler.s +++ b/c64/kernal/interrupts/fe66.default_brk_handler.s @@ -1,9 +1,13 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + default_brk_handler: - // Implemented according to Compute's Mapping the Commodore 64, pages 73-74 + // Implemented according to Computes Mapping the Commodore 64, pages 73-74 - sei // disable IRQs, to be sure they won't interfere + sei // disable IRQs, to be sure they wont interfere ldx #$00 sta VIC_SCROLX // turn the display off - we want as little screen artifacts as possible @@ -13,8 +17,8 @@ default_brk_handler: jsr JRESTOR jsr JIOINIT - // Original routine calls just a part of CINT - but I'm not sure which one. Most likely it - // skips the PAL/NTSC check by calling $E518. I suspect bug in the original ROM, let's + // Original routine calls just a part of CINT - but I am not sure which one. Most likely it + // skips the PAL/NTSC check by calling $E518. I suspect bug in the original ROM, lets // call the whole CINT, just to be sure everything is initialized. jsr CINT diff --git a/c64/kernal/interrupts/fffa.vector_nmi.s b/c64/kernal/interrupts/fffa.vector_nmi.s index 19ee0ad8..c33c2602 100644 --- a/c64/kernal/interrupts/fffa.vector_nmi.s +++ b/c64/kernal/interrupts/fffa.vector_nmi.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // $FFFA - CPU NMI Hanlder // Uncontrovertial as this is also a CPU requirement. diff --git a/c64/kernal/interrupts/fffe.vector_irq.s b/c64/kernal/interrupts/fffe.vector_irq.s index fd3e136d..755e9c57 100644 --- a/c64/kernal/interrupts/fffe.vector_irq.s +++ b/c64/kernal/interrupts/fffe.vector_irq.s @@ -1,3 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // $FFFE - CPU IRQ Vector. // This is non-controvertial, as it is a 6502 CPU requirement, and we just have to point // it to whatever IRQ routine we make. diff --git a/c64/kernal/interrupts/hw_entry_irq.s b/c64/kernal/interrupts/hw_entry_irq.s index e043ea0f..8177de7c 100644 --- a/c64/kernal/interrupts/hw_entry_irq.s +++ b/c64/kernal/interrupts/hw_entry_irq.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + hw_entry_irq: @@ -5,11 +9,11 @@ hw_entry_irq: // so we need to handle entry points that are commonly // relied upon, including: // $EA31 - Standard IRQ routine - // $EA61 - Check keyboard, but don't update timer? https://github.com/cc65/cc65/issues/324 + // $EA61 - Check keyboard, but do not update timer? https://github.com/cc65/cc65/issues/324 // $EA81 - https://www.lemon64.com/forum/viewtopic.php?t=2112&sid=6ea01982b26da69783120a7923ca46fb // Also the $0314 vector is widely used (e.g., https://www.lemon64.com/forum/viewtopic.php?t=2112&sid=6ea01982b26da69783120a7923ca46fb) - // Save registers, sequence according to Compute's Mapping the Commodore 64, page 73 + // Save registers, sequence according to Computes Mapping the Commodore 64, page 73 pha phx_trash_a phy_trash_a diff --git a/c64/kernal/interrupts/hw_entry_nmi.s b/c64/kernal/interrupts/hw_entry_nmi.s index ca41e1d0..2ed19829 100644 --- a/c64/kernal/interrupts/hw_entry_nmi.s +++ b/c64/kernal/interrupts/hw_entry_nmi.s @@ -1,7 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + hw_entry_nmi: - sei // don't allow IRQ to interfere, see https://www.c64-wiki.com/wiki/Interrupt + sei // do not allow IRQ to interfere, see https://www.c64-wiki.com/wiki/Interrupt #if CONFIG_CPU_MOS_6502 && CONFIG_BCD_SAFE_INTERRUPTS cld // clear decimal flag to allow using it without disabling interrupts diff --git a/c64/kernal/iostack/chkinout.s b/c64/kernal/iostack/chkinout.s index c8d3bda8..1d7c2043 100644 --- a/c64/kernal/iostack/chkinout.s +++ b/c64/kernal/iostack/chkinout.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Common part of CHKIN and CKOUT diff --git a/c64/kernal/iostack/clall_real.s b/c64/kernal/iostack/clall_real.s index abdd9b69..7243d7d6 100644 --- a/c64/kernal/iostack/clall_real.s +++ b/c64/kernal/iostack/clall_real.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 281 -// - [CM64] Compute's Mapping the Commodore 64 - page 230 +// - [RG64] C64 Programmers Reference Guide - page 281 +// - [CM64] Computes Mapping the Commodore 64 - page 230 // // CPU registers that has to be preserved (see [RG64]): .Y // @@ -16,7 +19,7 @@ clall_real: // Original routine probably just sets LDTND to 0, but this is not really safe, // so we actually close all the channels; at least IDE64 does the same for - // it's channels, see CLALL description in the IDE64 User's Guide + // its channels, see CLALL description in the IDE64 Users Guide !: ldy LDTND beq !+ @@ -33,4 +36,3 @@ clall_real: // Not sure whether original Kernal does so, but it seems sane to also clear possible errors jmp kernalstatus_reset - diff --git a/c64/kernal/iostack/f13e.getin.s b/c64/kernal/iostack/f13e.getin.s index 02d68bc3..c3017601 100644 --- a/c64/kernal/iostack/f13e.getin.s +++ b/c64/kernal/iostack/f13e.getin.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 283 -// - [CM64] Compute's Mapping the Commodore 64 - page 227/228 +// - [RG64] C64 Programmers Reference Guide - page 283 +// - [CM64] Computes Mapping the Commodore 64 - page 227/228 // // CPU registers that has to be preserved (see [RG64]): for RS-232: .X, .Y // diff --git a/c64/kernal/iostack/f157.chrin.s b/c64/kernal/iostack/f157.chrin.s index f4deafb3..b663cd93 100644 --- a/c64/kernal/iostack/f157.chrin.s +++ b/c64/kernal/iostack/f157.chrin.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 277/278 -// - [CM64] Compute's Mapping the Commodore 64 - page 228 +// - [RG64] C64 Programmers Reference Guide - page 277/278 +// - [CM64] Computes Mapping the Commodore 64 - page 228 // // CPU registers that has to be preserved (see [RG64]): .Y // @@ -19,17 +22,17 @@ CHRIN: lda DFLTN // Try $00 - keyboard - beq_far chrin_keyboard + beq_16 chrin_keyboard // XXX Try $03 - screen // cmp #$03 - // beq_far chrin_screen + // beq_16 chrin_screen #if HAS_RS232 // Try $02 - RS-232 cmp #$02 - beq_far chrin_rs232 + beq_16 chrin_rs232 #endif // HAS_RS232 @@ -39,7 +42,7 @@ chrin_getin: // jump entry for GETIN // Try IEC devices jsr iec_check_devnum_oc - bcc_far chrin_iec + bcc_16 chrin_iec #endif // CONFIG_IEC diff --git a/c64/kernal/iostack/f1ca.chrout.s b/c64/kernal/iostack/f1ca.chrout.s index 5c123847..b528a8bb 100644 --- a/c64/kernal/iostack/f1ca.chrout.s +++ b/c64/kernal/iostack/f1ca.chrout.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 278/279 -// - [CM64] Compute's Mapping the Commodore 64 - page 228 +// - [RG64] C64 Programmers Reference Guide - page 278/279 +// - [CM64] Computes Mapping the Commodore 64 - page 228 // // CPU registers that has to be preserved (see [RG64]): .Y // Additionally we have to preserve .X for out CHRIN and implementation @@ -15,7 +18,7 @@ CHROUT: // Save X and Y values // (Confirmed by writing a test program that X and Y - // don't get modified, in agreement with C64 PRG's + // do not get modified, in agreement with C64 PRG // description of CHROUT) phx_trash_a @@ -27,16 +30,16 @@ CHROUT: lda DFLTO cmp #$03 // screen - beq_far chrout_screen + beq_16 chrout_screen #if HAS_RS232 cmp #$02 - beq_far chrout_rs232 + beq_16 chrout_rs232 #endif #if CONFIG_IEC jsr iec_check_devnum_oc - bcc_far chrout_iec + bcc_16 chrout_iec #endif // FALLTROUGH @@ -66,6 +69,7 @@ chrout_done_unknown_device: chrout_done_success: plp + cli // needed for screen (checked calling the routine on original ROMs), XXX what about other devices? // Restore X and Y ply_trash_a diff --git a/c64/kernal/iostack/f20e.chkin.s b/c64/kernal/iostack/f20e.chkin.s index bd86226c..99259751 100644 --- a/c64/kernal/iostack/f20e.chkin.s +++ b/c64/kernal/iostack/f20e.chkin.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routines, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 275 -// - [CM64] Compute's Mapping the Commodore 64 - page 229 +// - [RG64] C64 Programmers Reference Guide - page 275 +// - [CM64] Computes Mapping the Commodore 64 - page 229 // // CPU registers that has to be preserved (see [RG64]): .Y, .A (see [CM64], page 213) // @@ -22,7 +25,7 @@ CHKIN: txa jsr find_fls - bcs_far chkinout_file_not_open + bcs_16 chkinout_file_not_open // Now we have table index in Y @@ -37,19 +40,19 @@ CHKIN: #if HAS_RS232 cmp #$02 - beq_far chkin_rs232 + beq_16 chkin_rs232 #endif // HAS_RS232 #if CONFIG_IEC jsr iec_check_devnum_oc - bcc_far chkin_iec + bcc_16 chkin_iec #endif // CONFIG_IEC cmp #$03 // screen - only legal one left - bne_far chkinout_device_not_present + bne_16 chkinout_device_not_present chkin_set_device: lda FAT,Y diff --git a/c64/kernal/iostack/f250.ckout.s b/c64/kernal/iostack/f250.ckout.s index 49a4d6a7..a99f359e 100644 --- a/c64/kernal/iostack/f250.ckout.s +++ b/c64/kernal/iostack/f250.ckout.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routines, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 276 -// - [CM64] Compute's Mapping the Commodore 64 - page 229 +// - [RG64] C64 Programmers Reference Guide - page 276 +// - [CM64] Computes Mapping the Commodore 64 - page 229 // // CPU registers that has to be preserved (see [RG64]): .Y, .A (see [CM64], page 213) // @@ -22,7 +25,7 @@ CKOUT: txa jsr find_fls - bcs_far chkinout_file_not_open + bcs_16 chkinout_file_not_open // Now we have table index in Y @@ -37,19 +40,19 @@ CKOUT: #if HAS_RS232 cmp #$02 - beq_far ckout_rs232 + beq_16 ckout_rs232 #endif // HAS_RS232 #if CONFIG_IEC jsr iec_check_devnum_oc - bcc_far ckout_iec + bcc_16 ckout_iec #endif // CONFIG_IEC cmp #$03 // screen - only legal one left - bne_far chkinout_device_not_present + bne_16 chkinout_device_not_present ckout_set_device: lda FAT,Y @@ -60,17 +63,3 @@ ckout_file_not_output: ply_trash_a pla jmp kernalerror_FILE_NOT_OUTPUT - - - - - - - - - - - - - - diff --git a/c64/kernal/iostack/f291.close.s b/c64/kernal/iostack/f291.close.s index c4930447..1a5b49a6 100644 --- a/c64/kernal/iostack/f291.close.s +++ b/c64/kernal/iostack/f291.close.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 281/282 -// - [CM64] Compute's Mapping the Commodore 64 - page 229/230 +// - [RG64] C64 Programmers Reference Guide - page 281/282 +// - [CM64] Computes Mapping the Commodore 64 - page 229/230 // - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc (IEC command) // // CPU registers that has to be preserved (see [RG64]): none @@ -24,12 +27,12 @@ CLOSE: #if HAS_RS232 cmp #$02 - beq_far close_rs232 + beq_16 close_rs232 #endif #if CONFIG_IEC jsr iec_check_devnum_oc - bcc_far close_iec + bcc_16 close_iec #endif // FALLTROUGH @@ -51,7 +54,7 @@ close_remove_from_table: // Decrement the list size variable dec LDTND - clc // report success - not sure if original CLOSE does this, but it's nevertheless a good practice + clc // report success - not sure if original CLOSE does this, but it is nevertheless a good practice close_end: rts diff --git a/c64/kernal/iostack/f32f.clall.jmp.s b/c64/kernal/iostack/f32f.clall.jmp.s index f0538e90..3305e94a 100644 --- a/c64/kernal/iostack/f32f.clall.jmp.s +++ b/c64/kernal/iostack/f32f.clall.jmp.s @@ -1,6 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Our implementation is longer than the original one, // placing it here would cause a collision with CLRCHN + CLALL: jmp clall_real diff --git a/c64/kernal/iostack/f333.clrchn.s b/c64/kernal/iostack/f333.clrchn.s index ab94909f..7e316739 100644 --- a/c64/kernal/iostack/f333.clrchn.s +++ b/c64/kernal/iostack/f333.clrchn.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 282 -// - [CM64] Compute's Mapping the Commodore 64 - page 230 +// - [RG64] C64 Programmers Reference Guide - page 282 +// - [CM64] Computes Mapping the Commodore 64 - page 230 // // CPU registers that has to be preserved (see [RG64]): .Y // diff --git a/c64/kernal/iostack/f34a.open.s b/c64/kernal/iostack/f34a.open.s index 3dc0e134..6387bdf1 100644 --- a/c64/kernal/iostack/f34a.open.s +++ b/c64/kernal/iostack/f34a.open.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 289 -// - [CM64] Compute's Mapping the Commodore 64 - page 230/231 +// - [RG64] C64 Programmers Reference Guide - page 289 +// - [CM64] Computes Mapping the Commodore 64 - page 230/231 // // CPU registers that has to be preserved (see [RG64]): none // @@ -42,7 +45,7 @@ open_has_space: // Update the tables // LAT / FAT / SAT support implemented according to - // 'Compute's Mapping the Commodore 64', page 52 + // 'Computes Mapping the Commodore 64', page 52 lda LA sta LAT, y @@ -59,14 +62,14 @@ open_has_space: #if HAS_RS232 cmp #$02 - beq_far open_rs232 + beq_16 open_rs232 #endif #if CONFIG_IEC jsr iec_check_devnum_oc - bcc_far open_iec + bcc_16 open_iec #endif diff --git a/c64/kernal/iostack/f49e.load_prep.s b/c64/kernal/iostack/f49e.load_prep.s index cc045026..6d71806c 100644 --- a/c64/kernal/iostack/f49e.load_prep.s +++ b/c64/kernal/iostack/f49e.load_prep.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // LOAD preparation routine diff --git a/c64/kernal/iostack/f4a5.load.s b/c64/kernal/iostack/f4a5.load.s index 2f173766..7c39a23e 100644 --- a/c64/kernal/iostack/f4a5.load.s +++ b/c64/kernal/iostack/f4a5.load.s @@ -1,8 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 286 -// - [CM64] Compute's Mapping the Commodore 64 - page 231 +// - [RG64] C64 Programmers Reference Guide - page 286 +// - [CM64] Computes Mapping the Commodore 64 - page 231 // - IEC reference at http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // // CPU registers that has to be preserved (see [RG64]): none @@ -41,17 +45,17 @@ LOAD: #if CONFIG_TAPE_NORMAL cmp #$01 - beq_far load_tape_normal + beq_16 load_tape_normal #endif #if CONFIG_TAPE_TURBO cmp #$07 - beq_far load_tape_turbo + beq_16 load_tape_turbo #endif #if CONFIG_IEC jsr iec_check_devnum_lvs - bcc_far load_iec + bcc_16 load_iec #endif jmp lvs_illegal_device_number diff --git a/c64/kernal/iostack/f5dd.save_prep.s b/c64/kernal/iostack/f5dd.save_prep.s index d7cf3f86..be34baea 100644 --- a/c64/kernal/iostack/f5dd.save_prep.s +++ b/c64/kernal/iostack/f5dd.save_prep.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // SAVE preparation routine diff --git a/c64/kernal/iostack/f5ed.save.s b/c64/kernal/iostack/f5ed.save.s index d8d053bf..caf08d01 100644 --- a/c64/kernal/iostack/f5ed.save.s +++ b/c64/kernal/iostack/f5ed.save.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 293/294 -// - [CM64] Compute's Mapping the Commodore 64 - page 231/232 +// - [RG64] C64 Programmers Reference Guide - page 293/294 +// - [CM64] Computes Mapping the Commodore 64 - page 231/232 // - IEC reference at http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf // // CPU registers that has to be preserved (see [RG64]): none @@ -24,7 +27,7 @@ SAVE: #if CONFIG_IEC jsr iec_check_devnum_lvs - bcc_far save_iec + bcc_16 save_iec #endif jmp lvs_illegal_device_number diff --git a/c64/kernal/iostack/findfls.s b/c64/kernal/iostack/findfls.s index 9da38026..52c04c5a 100644 --- a/c64/kernal/iostack/findfls.s +++ b/c64/kernal/iostack/findfls.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // Just a helper routine @@ -20,4 +23,3 @@ find_fls_not_found: sec rts - diff --git a/c64/kernal/iostack/getin_real.s b/c64/kernal/iostack/getin_real.s index 681e2a17..335c0319 100644 --- a/c64/kernal/iostack/getin_real.s +++ b/c64/kernal/iostack/getin_real.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 283 -// - [CM64] Compute's Mapping the Commodore 64 - page 227/228 +// - [RG64] C64 Programmers Reference Guide - page 283 +// - [CM64] Computes Mapping the Commodore 64 - page 227/228 // // CPU registers that has to be preserved (see [RG64]): for RS-232: .X, .Y // @@ -15,13 +18,13 @@ getin_real: lda DFLTN // Try $00 - keyboard - beq_far getin_keyboard + beq_16 getin_keyboard #if HAS_RS232 // Try $02 - RS-232 cmp #$02 - beq_far getin_rs232 + beq_16 getin_rs232 #endif // HAS_RS232 diff --git a/c64/kernal/iostack/load_save_common.s b/c64/kernal/iostack/load_save_common.s index a2d31714..7e6e0fb2 100644 --- a/c64/kernal/iostack/load_save_common.s +++ b/c64/kernal/iostack/load_save_common.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper functions for various LOAD/VERIFY/SAVE routine variants (IEC / U64 / etc.) @@ -103,6 +106,7 @@ lvs_advance_MEMUSS: #endif + lvs_check_EAL: lda MEMUSS+1 @@ -223,7 +227,6 @@ lvs_display_saving: !: rts - lvs_error_end: sec @@ -231,7 +234,7 @@ lvs_error_end: lvs_return_last_address: - // Return last address - Compute's Mapping the 64 says without the '+1', + // Return last address - Computes Mapping the 64 says without the '+1', // checked (short test program) on original ROMs that this is really the case ldx EAL+0 ldy EAL+1 @@ -242,6 +245,8 @@ lvs_success_end: clc rts +#endif + lvs_device_not_found_error: jsr kernalstatus_DEVICE_NOT_FOUND @@ -252,6 +257,8 @@ lvs_illegal_device_number: jsr kernalstatus_DEVICE_NOT_FOUND jmp kernalerror_ILLEGAL_DEVICE_NUMBER +#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO || CONFIG_IEC + lvs_load_verify_error: // XXX should we really return BASIC error code here? lda VERCKK @@ -264,3 +271,5 @@ lvs_verify_error: lda #B_ERR_VERIFY sec rts + +#endif diff --git a/c64/kernal/iostack/readst.s b/c64/kernal/iostack/readst.s index 10a7d11f..2c103c4b 100644 --- a/c64/kernal/iostack/readst.s +++ b/c64/kernal/iostack/readst.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 292 -// - [CM64] Compute's Mapping the Commodore 64 - page 239 +// - [RG64] C64 Programmers Reference Guide - page 292 +// - [CM64] Computes Mapping the Commodore 64 - page 239 // // CPU registers that has to be preserved (see [RG64]): .X, .Y // @@ -16,13 +19,13 @@ READST: cmp #$02 bne !+ - // This is RS-232 device - according to 'Compute's Mapping the Commodore 64' page 239 + // This is RS-232 device - according to 'Computes Mapping the Commodore 64' page 239 // it reads status from RSSTAT // XXX 'lda RSSTAT' not possible due to extended scnkey, fix it! lda #$FF rts !: - // According to 'Compute's Mapping the Commodore 64' page 239, it usually retrieves + // According to 'Computes Mapping the Commodore 64' page 239, it usually retrieves // status from IOSTATUS // XXX is it always the case if device is not RS-232 ? diff --git a/c64/kernal/iostack/setfls.s b/c64/kernal/iostack/setfls.s index d57f770b..086124d3 100644 --- a/c64/kernal/iostack/setfls.s +++ b/c64/kernal/iostack/setfls.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 297 -// - [CM64] Compute's Mapping the Commodore 64 - page 238 +// - [RG64] C64 Programmers Reference Guide - page 297 +// - [CM64] Computes Mapping the Commodore 64 - page 238 // // CPU registers that has to be preserved (see [RG64]): .A, .X, .Y // @@ -11,7 +14,7 @@ SETFLS: // There are 6 sane ways to implement this routine, - // I hope this one won't cause similarity to CBM code + // I hope this one will not cause similarity to CBM code sta LA sty SA diff --git a/c64/kernal/iostack/setmsg.s b/c64/kernal/iostack/setmsg.s index 87b1125f..5465e3c8 100644 --- a/c64/kernal/iostack/setmsg.s +++ b/c64/kernal/iostack/setmsg.s @@ -1,13 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 298 -// - [CM64] Compute's Mapping the Commodore 64 - page 239 +// - [RG64] C64 Programmers Reference Guide - page 298 +// - [CM64] Computes Mapping the Commodore 64 - page 239 // // CPU registers that has to be preserved (see [RG64]): .A, .X, .Y // SETMSG: + sta MSGFLG rts diff --git a/c64/kernal/iostack/setnam.s b/c64/kernal/iostack/setnam.s index 78033a3c..fd13b15a 100644 --- a/c64/kernal/iostack/setnam.s +++ b/c64/kernal/iostack/setnam.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 298/299 -// - [CM64] Compute's Mapping the Commodore 64 - page 238 +// - [RG64] C64 Programmers Reference Guide - page 298/299 +// - [CM64] Computes Mapping the Commodore 64 - page 238 // // CPU registers that has to be preserved (see [RG64]): .A, .X, .Y // @@ -11,7 +14,7 @@ SETNAM: // There are 6 sane ways to implement this routine, - // I hope this one won't cause similarity to CBM code + // I hope this one will not cause similarity to CBM code sta FNLEN sty FNADDR + 1 diff --git a/c64/kernal/iostack/settmo.s b/c64/kernal/iostack/settmo.s index 16f84c40..1c100118 100644 --- a/c64/kernal/iostack/settmo.s +++ b/c64/kernal/iostack/settmo.s @@ -1,13 +1,18 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 300 -// - [CM64] Compute's Mapping the Commodore 64 - page 239 +// - [RG64] C64 Programmers Reference Guide - page 300 +// - [CM64] Computes Mapping the Commodore 64 - page 239 // // CPU registers that has to be preserved (see [RG64]): .A, .X, .Y // + SETTMO: + sta TIMOUT rts diff --git a/c64/kernal/jumptable/ff81.jcint.s b/c64/kernal/jumptable/ff81.jcint.s index ea93a325..c15b3754 100644 --- a/c64/kernal/jumptable/ff81.jcint.s +++ b/c64/kernal/jumptable/ff81.jcint.s @@ -1,4 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // Initialise screen editor -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp CINT diff --git a/c64/kernal/jumptable/ff84.jioinit.s b/c64/kernal/jumptable/ff84.jioinit.s index fda7c62c..4aec4521 100644 --- a/c64/kernal/jumptable/ff84.jioinit.s +++ b/c64/kernal/jumptable/ff84.jioinit.s @@ -1,4 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + // Initialise input/output -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp IOINIT diff --git a/c64/kernal/jumptable/ff87.jramtas.s b/c64/kernal/jumptable/ff87.jramtas.s index 616021c5..5e0b2f47 100644 --- a/c64/kernal/jumptable/ff87.jramtas.s +++ b/c64/kernal/jumptable/ff87.jramtas.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Initialise RAM, allocate tape buffer, set screen to $0400 -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp RAMTAS diff --git a/c64/kernal/jumptable/ff8a.jrestor.s b/c64/kernal/jumptable/ff8a.jrestor.s index 0fa0057e..b424d743 100644 --- a/c64/kernal/jumptable/ff8a.jrestor.s +++ b/c64/kernal/jumptable/ff8a.jrestor.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Restore default IO vectors -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp RESTOR diff --git a/c64/kernal/jumptable/ff8d.jvector.s b/c64/kernal/jumptable/ff8d.jvector.s index cd0b9990..473164b5 100644 --- a/c64/kernal/jumptable/ff8d.jvector.s +++ b/c64/kernal/jumptable/ff8d.jvector.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Read/set vectored I/O -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp VECTOR diff --git a/c64/kernal/jumptable/ff90.jsetmsg.s b/c64/kernal/jumptable/ff90.jsetmsg.s index 7f54b3ac..7f68b5d0 100644 --- a/c64/kernal/jumptable/ff90.jsetmsg.s +++ b/c64/kernal/jumptable/ff90.jsetmsg.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Control KERNAL messages -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SETMSG diff --git a/c64/kernal/jumptable/ff93.jsecond.s b/c64/kernal/jumptable/ff93.jsecond.s index 6ae355f0..afe4fc44 100644 --- a/c64/kernal/jumptable/ff93.jsecond.s +++ b/c64/kernal/jumptable/ff93.jsecond.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Send secondary address after LISTEN -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SECOND diff --git a/c64/kernal/jumptable/ff96.jtksa.s b/c64/kernal/jumptable/ff96.jtksa.s index 5f710af0..5045e23e 100644 --- a/c64/kernal/jumptable/ff96.jtksa.s +++ b/c64/kernal/jumptable/ff96.jtksa.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Send secondary address after talk -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp TKSA diff --git a/c64/kernal/jumptable/ff99.jmemtop.s b/c64/kernal/jumptable/ff99.jmemtop.s index b6653e94..69516338 100644 --- a/c64/kernal/jumptable/ff99.jmemtop.s +++ b/c64/kernal/jumptable/ff99.jmemtop.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // read/set the top of memory -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp MEMTOP diff --git a/c64/kernal/jumptable/ff9c.jmembot.s b/c64/kernal/jumptable/ff9c.jmembot.s index 8745f99b..557f9b68 100644 --- a/c64/kernal/jumptable/ff9c.jmembot.s +++ b/c64/kernal/jumptable/ff9c.jmembot.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // read/set the bottom of memory -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp MEMBOT diff --git a/c64/kernal/jumptable/ff9f.jscnkey.s b/c64/kernal/jumptable/ff9f.jscnkey.s index 5d71d27d..b7fba783 100644 --- a/c64/kernal/jumptable/ff9f.jscnkey.s +++ b/c64/kernal/jumptable/ff9f.jscnkey.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Scan keyboard -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SCNKEY diff --git a/c64/kernal/jumptable/ffa2.jsettmo.s b/c64/kernal/jumptable/ffa2.jsettmo.s index 3d82b696..c96e8219 100644 --- a/c64/kernal/jumptable/ffa2.jsettmo.s +++ b/c64/kernal/jumptable/ffa2.jsettmo.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Set timeout on serial bus -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SETTMO diff --git a/c64/kernal/jumptable/ffa5.jacptr.s b/c64/kernal/jumptable/ffa5.jacptr.s index 6446229f..c9e23a6b 100644 --- a/c64/kernal/jumptable/ffa5.jacptr.s +++ b/c64/kernal/jumptable/ffa5.jacptr.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Input byte from serial port -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp ACPTR diff --git a/c64/kernal/jumptable/ffa8.jciout.s b/c64/kernal/jumptable/ffa8.jciout.s index 2838110a..92f58234 100644 --- a/c64/kernal/jumptable/ffa8.jciout.s +++ b/c64/kernal/jumptable/ffa8.jciout.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Output byte to serial port -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp CIOUT diff --git a/c64/kernal/jumptable/ffab.juntlk.s b/c64/kernal/jumptable/ffab.juntlk.s index dc6ebbe0..bb061270 100644 --- a/c64/kernal/jumptable/ffab.juntlk.s +++ b/c64/kernal/jumptable/ffab.juntlk.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Command serial bus to UNTALK -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp UNTLK diff --git a/c64/kernal/jumptable/ffae.junlsn.s b/c64/kernal/jumptable/ffae.junlsn.s index 55cab36f..98eba47e 100644 --- a/c64/kernal/jumptable/ffae.junlsn.s +++ b/c64/kernal/jumptable/ffae.junlsn.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Command serial bus to UNLISTEN -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp UNLSN diff --git a/c64/kernal/jumptable/ffb1.jlisten.s b/c64/kernal/jumptable/ffb1.jlisten.s index e93c9be8..c8f24e27 100644 --- a/c64/kernal/jumptable/ffb1.jlisten.s +++ b/c64/kernal/jumptable/ffb1.jlisten.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Command devices on the serial bus to listen -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp LISTEN diff --git a/c64/kernal/jumptable/ffb4.jtalk.s b/c64/kernal/jumptable/ffb4.jtalk.s index f94fffd3..6c682674 100644 --- a/c64/kernal/jumptable/ffb4.jtalk.s +++ b/c64/kernal/jumptable/ffb4.jtalk.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Command serial bus device to talk -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp TALK diff --git a/c64/kernal/jumptable/ffb7.jreadst.s b/c64/kernal/jumptable/ffb7.jreadst.s index 46fcc2fd..bfd9e0ef 100644 --- a/c64/kernal/jumptable/ffb7.jreadst.s +++ b/c64/kernal/jumptable/ffb7.jreadst.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Read I/O statusjmp -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp READST diff --git a/c64/kernal/jumptable/ffba.jsetfls.s b/c64/kernal/jumptable/ffba.jsetfls.s index ec77c14a..55021177 100644 --- a/c64/kernal/jumptable/ffba.jsetfls.s +++ b/c64/kernal/jumptable/ffba.jsetfls.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Set logical, first and second addresses -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SETFLS diff --git a/c64/kernal/jumptable/ffbd.jsetnam.s b/c64/kernal/jumptable/ffbd.jsetnam.s index e0e3871e..1bb61381 100644 --- a/c64/kernal/jumptable/ffbd.jsetnam.s +++ b/c64/kernal/jumptable/ffbd.jsetnam.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Set file name -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SETNAM diff --git a/c64/kernal/jumptable/ffc0.jopen.s b/c64/kernal/jumptable/ffc0.jopen.s index 82a5aa1b..a72b8652 100644 --- a/c64/kernal/jumptable/ffc0.jopen.s +++ b/c64/kernal/jumptable/ffc0.jopen.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // open a logical file -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (IOPEN) diff --git a/c64/kernal/jumptable/ffc3.jclose.s b/c64/kernal/jumptable/ffc3.jclose.s index badb18c8..5e97e0e5 100644 --- a/c64/kernal/jumptable/ffc3.jclose.s +++ b/c64/kernal/jumptable/ffc3.jclose.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // close a specified logical file -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (ICLOSE) diff --git a/c64/kernal/jumptable/ffc6.jchkin.s b/c64/kernal/jumptable/ffc6.jchkin.s index b06874ef..5d2aaf98 100644 --- a/c64/kernal/jumptable/ffc6.jchkin.s +++ b/c64/kernal/jumptable/ffc6.jchkin.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Open channel for input -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (ICHKIN) diff --git a/c64/kernal/jumptable/ffc9.jckout.s b/c64/kernal/jumptable/ffc9.jckout.s index 64ff0481..e68fe86e 100644 --- a/c64/kernal/jumptable/ffc9.jckout.s +++ b/c64/kernal/jumptable/ffc9.jckout.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Open channel for output -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (ICKOUT) diff --git a/c64/kernal/jumptable/ffcc.jclrchn.s b/c64/kernal/jumptable/ffcc.jclrchn.s index a207f2e4..d1e444a4 100644 --- a/c64/kernal/jumptable/ffcc.jclrchn.s +++ b/c64/kernal/jumptable/ffcc.jclrchn.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // close input and output channels -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (ICLRCH) diff --git a/c64/kernal/jumptable/ffcf.jchrin.s b/c64/kernal/jumptable/ffcf.jchrin.s index de1ae44e..08cab5fd 100644 --- a/c64/kernal/jumptable/ffcf.jchrin.s +++ b/c64/kernal/jumptable/ffcf.jchrin.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Input character from channel -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (IBASIN) diff --git a/c64/kernal/jumptable/ffd2.jchrout.s b/c64/kernal/jumptable/ffd2.jchrout.s index c3f31a0e..fb7b6a7d 100644 --- a/c64/kernal/jumptable/ffd2.jchrout.s +++ b/c64/kernal/jumptable/ffd2.jchrout.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Output character to channel -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (IBSOUT) diff --git a/c64/kernal/jumptable/ffd5.jload.s b/c64/kernal/jumptable/ffd5.jload.s index 002e01fd..a428cb1d 100644 --- a/c64/kernal/jumptable/ffd5.jload.s +++ b/c64/kernal/jumptable/ffd5.jload.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // load RAM from a device -// C64 Programmer's Reference Guide Page 272 +// C64 Programmers Reference Guide Page 272 jmp LOAD_PREP diff --git a/c64/kernal/jumptable/ffd8.jsave.s b/c64/kernal/jumptable/ffd8.jsave.s index 25f3fbec..5f755e2b 100644 --- a/c64/kernal/jumptable/ffd8.jsave.s +++ b/c64/kernal/jumptable/ffd8.jsave.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // SAVE RAM to device -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SAVE_PREP diff --git a/c64/kernal/jumptable/ffdb.jsettim.s b/c64/kernal/jumptable/ffdb.jsettim.s index 61625a29..3c0e6111 100644 --- a/c64/kernal/jumptable/ffdb.jsettim.s +++ b/c64/kernal/jumptable/ffdb.jsettim.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Set realtime clock -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp SETTIM diff --git a/c64/kernal/jumptable/ffde.jrdtim.s b/c64/kernal/jumptable/ffde.jrdtim.s index 5a190b14..5ec9a17a 100644 --- a/c64/kernal/jumptable/ffde.jrdtim.s +++ b/c64/kernal/jumptable/ffde.jrdtim.s @@ -1,4 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Read real time clock -// C64 Programmer's Reference Guide Page 273 +// C64 Programmers Reference Guide Page 273 jmp RDTIM diff --git a/c64/kernal/jumptable/ffe1.jstop.s b/c64/kernal/jumptable/ffe1.jstop.s index 0938b7d1..980b669f 100644 --- a/c64/kernal/jumptable/ffe1.jstop.s +++ b/c64/kernal/jumptable/ffe1.jstop.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Scan stop key -// C64 Programmer's Reference Guide Page 273 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 273 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (ISTOP) diff --git a/c64/kernal/jumptable/ffe4.jgetin.s b/c64/kernal/jumptable/ffe4.jgetin.s index feafd28c..e927c5f5 100644 --- a/c64/kernal/jumptable/ffe4.jgetin.s +++ b/c64/kernal/jumptable/ffe4.jgetin.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // Get character from keyboard queue (keyboard buffer) -// C64 Programmer's Reference Guide Page 272 -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// C64 Programmers Reference Guide Page 272 +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (IGETIN) diff --git a/c64/kernal/jumptable/ffe7.jclall.s b/c64/kernal/jumptable/ffe7.jclall.s index 287f85ac..a5b9fb65 100644 --- a/c64/kernal/jumptable/ffe7.jclall.s +++ b/c64/kernal/jumptable/ffe7.jclall.s @@ -1,5 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // $FFE7 - Close all files vector // (http://codebase64.org/doku.php?id=base:kernalreference) -// According to Compute's Mapping the Commodore 64 (pages 74/75), this jump is indirect +// According to Computes Mapping the Commodore 64 (pages 74/75), this jump is indirect jmp (ICLALL) diff --git a/c64/kernal/jumptable/ffea.judtim.s b/c64/kernal/jumptable/ffea.judtim.s index bccd0603..d4545c64 100644 --- a/c64/kernal/jumptable/ffea.judtim.s +++ b/c64/kernal/jumptable/ffea.judtim.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // $FFEA - Update jiffy clock vector // (http://codebase64.org/doku.php?id=base:kernalreference) diff --git a/c64/kernal/jumptable/ffed.jscreen.s b/c64/kernal/jumptable/ffed.jscreen.s index 8f58f3f2..815f9614 100644 --- a/c64/kernal/jumptable/ffed.jscreen.s +++ b/c64/kernal/jumptable/ffed.jscreen.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // $FFED - Return screen size (X=columns, Y=rows) // (http://codebase64.org/doku.php?id=base:kernalreference) diff --git a/c64/kernal/jumptable/fff0.jplot.s b/c64/kernal/jumptable/fff0.jplot.s index 2a9f782c..f6206f9a 100644 --- a/c64/kernal/jumptable/fff0.jplot.s +++ b/c64/kernal/jumptable/fff0.jplot.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // $FFF0 - Get/Set cursor location vector // (http://codebase64.org/doku.php?id=base:kernalreference) // To set: C=0, to get, C=1 diff --git a/c64/kernal/jumptable/fff3.jiobase.s b/c64/kernal/jumptable/fff3.jiobase.s index 3250765f..8f0b756b 100644 --- a/c64/kernal/jumptable/fff3.jiobase.s +++ b/c64/kernal/jumptable/fff3.jiobase.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 284 -// - [CM64] Compute's Mapping the Commodore 64 - page 214 +// - [RG64] C64 Programmers Reference Guide - page 284 +// - [CM64] Computes Mapping the Commodore 64 - page 214 // - http://codebase64.org/doku.php?id=base:kernalreference (original source) // // CPU registers that has to be preserved (see [RG64]): .A @@ -16,4 +19,3 @@ ldy #$DC ldx #$00 rts - diff --git a/c64/kernal/keyboard/chrin_keyboard.s b/c64/kernal/keyboard/chrin_keyboard.s index 40966536..afdf4515 100644 --- a/c64/kernal/keyboard/chrin_keyboard.s +++ b/c64/kernal/keyboard/chrin_keyboard.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Keyboard part of the CHRIN routine @@ -35,7 +38,7 @@ chrin_repeat: empty_line: // For an empty line, just return the carriage return - // (and don't forget to actually print the carriage return, so that + // (and do not forget to actually print the carriage return, so that // the cursor advances and screen scrolls as required) ply_trash_a @@ -81,7 +84,7 @@ chrin_enter: // It was enter. // Note that we have a line of input to return, and return the first byte thereof // after computing and storing its length. - // (Compute's Mapping the 64, p96) + // (Computes Mapping the 64, p96) // Set pointer to line of input lda PNT+0 @@ -89,15 +92,34 @@ chrin_enter: lda PNT+1 sta LXSP+1 + // If the current line is a continuation of the previous one, decrease LXSP by 40 + ldy TBLX + lda LDTBL, y + bmi chrin_enter_calc_length // branch if not continuation + lda LXSP+0 + sec + sbc #40 + sta LXSP+0 + bcs !+ + dec LXSP+1 +!: + ldy #80 + bne chrin_enter_loop // branch always + +chrin_enter_calc_length: + // Calculate length - jsr screen_get_current_line_logical_length - tay + jsr screen_get_logical_line_end_ptr iny -!: dey + +chrin_enter_loop: + + // Retrieve bytes + dey bmi empty_line - lda (PNT),y + lda (LXSP),y cmp #$20 - beq !- + beq chrin_enter_loop iny sty INDX lda #$01 diff --git a/c64/kernal/keyboard/f142.getin_keyboard.s b/c64/kernal/keyboard/f142.getin_keyboard.s index 3e3da159..51f1ec69 100644 --- a/c64/kernal/keyboard/f142.getin_keyboard.s +++ b/c64/kernal/keyboard/f142.getin_keyboard.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Well-known Kernal routine, described in: diff --git a/c64/kernal/keyboard/f6ed.stop.s b/c64/kernal/keyboard/f6ed.stop.s index 3f41b20a..4bd842ff 100644 --- a/c64/kernal/keyboard/f6ed.stop.s +++ b/c64/kernal/keyboard/f6ed.stop.s @@ -1,16 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 301 -// - [CM64] Compute's Mapping the Commodore 64 - page 232 +// - [RG64] C64 Programmers Reference Guide - page 301 +// - [CM64] Computes Mapping the Commodore 64 - page 232 // // CPU registers that has to be preserved (see [RG64]): .Y // STOP: // Bit 7 of STKEY contains the state of the STOP key - // (Compute's Mapping the 64, p27) + // (Computes Mapping the 64, p27) // BASIC checks carry flag to indicate STOP or not lda STKEY diff --git a/c64/kernal/keyboard/kb_matrix.s b/c64/kernal/keyboard/kb_matrix.s index b56631a5..57458aae 100644 --- a/c64/kernal/keyboard/kb_matrix.s +++ b/c64/kernal/keyboard/kb_matrix.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Keyboard matrix, based on // -// - [RG64] C64 Programmer's Reference Guide - pages 379-381 -// - [CM64] Compute's Mapping the Commodore 64 - pages 38-39 +// - [RG64] C64 Programmers Reference Guide - pages 379-381 +// - [CM64] Computes Mapping the Commodore 64 - pages 38-39 // - http://commodore128.mirkosoft.sk/keyboard.html (C128 extension) // - http://www.zimmers.net/cbmpics/cbm/c65/c65manual.txt diff --git a/c64/kernal/keyboard/kb_matrix_128.s b/c64/kernal/keyboard/kb_matrix_128.s index 85d09b7b..9009f8b9 100644 --- a/c64/kernal/keyboard/kb_matrix_128.s +++ b/c64/kernal/keyboard/kb_matrix_128.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Extended keyboard matrix for Commodore 128 keyboards, based on // -// - [CM128] Compute's Mapping the Commodore 128 - page 290 +// - [CM128] Computes Mapping the Commodore 128 - page 290 // - http://commodore128.mirkosoft.sk/keyboard.html // diff --git a/c64/kernal/keyboard/kb_matrix_65.s b/c64/kernal/keyboard/kb_matrix_65.s index 58986d02..eb50d79b 100644 --- a/c64/kernal/keyboard/kb_matrix_65.s +++ b/c64/kernal/keyboard/kb_matrix_65.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Extended keyboard matrix for Commodore 65 keyboards, based on diff --git a/c64/kernal/keyboard/kb_matrix_alwaysrepeat.s b/c64/kernal/keyboard/kb_matrix_alwaysrepeat.s index ffb80e02..b49d4943 100644 --- a/c64/kernal/keyboard/kb_matrix_alwaysrepeat.s +++ b/c64/kernal/keyboard/kb_matrix_alwaysrepeat.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Matrix ids of keys which should be repeated regardless of RPTFLG // // Values based on: -// - [CM64] Compute's Mapping the Commodore 64 - page 58 +// - [CM64] Computes Mapping the Commodore 64 - page 58 // diff --git a/c64/kernal/keyboard/kb_matrix_bucky.s b/c64/kernal/keyboard/kb_matrix_bucky.s index 2d67f574..089ffaef 100644 --- a/c64/kernal/keyboard/kb_matrix_bucky.s +++ b/c64/kernal/keyboard/kb_matrix_bucky.s @@ -1,10 +1,13 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Matrix for retrieving bucky key status on the C64 keyboard // // Values based on: -// - [CM64] Compute's Mapping the Commodore 64 - pages 58 (SHFLAG), 173 (matrix) -// - [CM128] Compute's Mapping the Commodore 128 - pages 212 (SHFLAG), 290 (matrix) +// - [CM64] Computes Mapping the Commodore 64 - pages 58 (SHFLAG), 173 (matrix) +// - [CM128] Computes Mapping the Commodore 128 - pages 212 (SHFLAG), 290 (matrix) // - https://github.com/MEGA65/c65-specifications/blob/master/c65manualupdated.txt // diff --git a/c64/kernal/keyboard/kb_matrix_bucky_filter.s b/c64/kernal/keyboard/kb_matrix_bucky_filter.s index 0e2a9b36..0c693c5d 100644 --- a/c64/kernal/keyboard/kb_matrix_bucky_filter.s +++ b/c64/kernal/keyboard/kb_matrix_bucky_filter.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Matrix for filtering out bucky keys while scanning the C64 keyboard // // Values based on: -// - [CM64] Compute's Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix) +// - [CM64] Computes Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix) // diff --git a/c64/kernal/keyboard/kb_matrix_joy.s b/c64/kernal/keyboard/kb_matrix_joy.s index 8f9deaab..d19644f1 100644 --- a/c64/kernal/keyboard/kb_matrix_joy.s +++ b/c64/kernal/keyboard/kb_matrix_joy.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Matrix for retrieving C64 joystick status and inject is as keyboard event diff --git a/c64/kernal/keyboard/kb_matrix_lookup.s b/c64/kernal/keyboard/kb_matrix_lookup.s index 9e1b8f34..1d9715fc 100644 --- a/c64/kernal/keyboard/kb_matrix_lookup.s +++ b/c64/kernal/keyboard/kb_matrix_lookup.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper table for determining keyboard matrix decoding table on the C64 keyboard diff --git a/c64/kernal/keyboard/kb_matrix_lookup_legacy.s b/c64/kernal/keyboard/kb_matrix_lookup_legacy.s index 62f2a932..b628921f 100644 --- a/c64/kernal/keyboard/kb_matrix_lookup_legacy.s +++ b/c64/kernal/keyboard/kb_matrix_lookup_legacy.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Work out if normal, shifted, control or Vendor modified keyboard. diff --git a/c64/kernal/keyboard/kb_matrix_row_keys.s b/c64/kernal/keyboard/kb_matrix_row_keys.s index bb4b9afb..21bab4f5 100644 --- a/c64/kernal/keyboard/kb_matrix_row_keys.s +++ b/c64/kernal/keyboard/kb_matrix_row_keys.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Single row key codes for scanning the C64 keyboard // // Values based on: -// - [CM64] Compute's Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix) +// - [CM64] Computes Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix) // diff --git a/c64/kernal/keyboard/kb_matrix_row_offsets.s b/c64/kernal/keyboard/kb_matrix_row_offsets.s index efc2ceaf..8b0b7d5a 100644 --- a/c64/kernal/keyboard/kb_matrix_row_offsets.s +++ b/c64/kernal/keyboard/kb_matrix_row_offsets.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper values to quickly determine row offset from the start of keyboard matrix diff --git a/c64/kernal/keyboard/keyboard_disconnect.s b/c64/kernal/keyboard/keyboard_disconnect.s index 1fdae023..5fb2bf73 100644 --- a/c64/kernal/keyboard/keyboard_disconnect.s +++ b/c64/kernal/keyboard/keyboard_disconnect.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routine - disconnects the keyboard from CIA1_PRB, diff --git a/c64/kernal/keyboard/pop_keyboard_buffer.s b/c64/kernal/keyboard/pop_keyboard_buffer.s index 6f3b172b..264d0a55 100644 --- a/c64/kernal/keyboard/pop_keyboard_buffer.s +++ b/c64/kernal/keyboard/pop_keyboard_buffer.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // Pop key out of keyboard buffer // Disable interrupts while reading from keyboard buffer diff --git a/c64/kernal/keyboard/programmable_keys.s b/c64/kernal/keyboard/programmable_keys.s index 1f31d204..181914e0 100644 --- a/c64/kernal/keyboard/programmable_keys.s +++ b/c64/kernal/keyboard/programmable_keys.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Command string definitions for programmable keys diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index 0aadfd93..003b38e5 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 295 -// - [CM64] Compute's Mapping the Commodore 64 - page 220 +// - [RG64] C64 Programmers Reference Guide - page 295 +// - [CM64] Computes Mapping the Commodore 64 - page 220 // // CPU registers that has to be preserved (see [RG64]): none // diff --git a/c64/kernal/keyboard/scnkey_128.s b/c64/kernal/keyboard/scnkey_128.s index dbbeecdf..48945214 100644 --- a/c64/kernal/keyboard/scnkey_128.s +++ b/c64/kernal/keyboard/scnkey_128.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Keyboard scanning routine extension for C128 keyboards // -// - [CM128] Compute's Mapping the Commodore 128 - pages 212 (SHFLAG), 290 (matrix) +// - [CM128] Computes Mapping the Commodore 128 - pages 212 (SHFLAG), 290 (matrix) // diff --git a/c64/kernal/keyboard/scnkey_65.s b/c64/kernal/keyboard/scnkey_65.s index 5d3f5b58..34584b72 100644 --- a/c64/kernal/keyboard/scnkey_65.s +++ b/c64/kernal/keyboard/scnkey_65.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Keyboard scanning routine extension for C65 keyboards // -// - [CM128] Compute's Mapping the Commodore 128 - pages 212 (SHFLAG) +// - [CM128] Computes Mapping the Commodore 128 - pages 212 (SHFLAG) // - https://github.com/MEGA65/c65-specifications/blob/master/c65manualupdated.txt (matrix) // @@ -61,5 +64,4 @@ scnkey_65_done: rts - #endif // CONFIG_KEYBOARD_C65 and no CONFIG_LEGACY_SCNKEY diff --git a/c64/kernal/keyboard/scnkey_legacy.s b/c64/kernal/keyboard/scnkey_legacy.s index fe25392b..42dae86f 100644 --- a/c64/kernal/keyboard/scnkey_legacy.s +++ b/c64/kernal/keyboard/scnkey_legacy.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 295 -// - [CM64] Compute's Mapping the Commodore 64 - page 220 +// - [RG64] C64 Programmers Reference Guide - page 295 +// - [CM64] Computes Mapping the Commodore 64 - page 220 // // CPU registers that has to be preserved (see [RG64]): none // diff --git a/c64/kernal/keyboard/scnkey_set_keytab.s b/c64/kernal/keyboard/scnkey_set_keytab.s index 6c9a03b1..c1da0a66 100644 --- a/c64/kernal/keyboard/scnkey_set_keytab.s +++ b/c64/kernal/keyboard/scnkey_set_keytab.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Well-known Kernal routine, described in: // -// - [CM64] Compute's Mapping the Commodore 64 - pages 220, 221 +// - [CM64] Computes Mapping the Commodore 64 - pages 220, 221 // diff --git a/c64/kernal/keyboard/udtim_keyboard.s b/c64/kernal/keyboard/udtim_keyboard.s index d35f86f6..35d6724a 100644 --- a/c64/kernal/keyboard/udtim_keyboard.s +++ b/c64/kernal/keyboard/udtim_keyboard.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Keyboard part of the UDTIM routine, has to preserve .Y diff --git a/c64/kernal/memory/fd15.restor.s b/c64/kernal/memory/fd15.restor.s index 5e181423..a4a5b106 100644 --- a/c64/kernal/memory/fd15.restor.s +++ b/c64/kernal/memory/fd15.restor.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 293 (RESTOR), 304 (VECTOR) -// - [CM64] Compute's Mapping the Commodore 64 - page 237 +// - [RG64] C64 Programmers Reference Guide - page 293 (RESTOR), 304 (VECTOR) +// - [CM64] Computes Mapping the Commodore 64 - page 237 // // CPU registers that has to be preserved (see [RG64]): none // diff --git a/c64/kernal/memory/fe25.memtop.s b/c64/kernal/memory/fe25.memtop.s index 960152b0..53685389 100644 --- a/c64/kernal/memory/fe25.memtop.s +++ b/c64/kernal/memory/fe25.memtop.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 288 -// - [CM64] Compute's Mapping the Commodore 64 - page 240 +// - [RG64] C64 Programmers Reference Guide - page 288 +// - [CM64] Computes Mapping the Commodore 64 - page 240 // // CPU registers that has to be preserved (see [RG64]): .A // diff --git a/c64/kernal/memory/membot.s b/c64/kernal/memory/membot.s index 84e6ce44..0da97fdc 100644 --- a/c64/kernal/memory/membot.s +++ b/c64/kernal/memory/membot.s @@ -1,9 +1,10 @@ +#if ROM_LAYOUT_STD || (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 287/288 -// - [CM64] Compute's Mapping the Commodore 64 - page 240 +// - [RG64] C64 Programmers Reference Guide - page 287/288 +// - [CM64] Computes Mapping the Commodore 64 - page 240 // // CPU registers that has to be preserved (see [RG64]): .A // @@ -23,3 +24,6 @@ membot_set: stx MEMSTR+0 rts + + +#endif // ROM layout diff --git a/c64/kernal/memory/under_rom_routines.s b/c64/kernal/memory/under_rom_routines.s index 5e45aa15..25de7830 100644 --- a/c64/kernal/memory/under_rom_routines.s +++ b/c64/kernal/memory/under_rom_routines.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // IMPORTANT: // These routines lengths cannot be changed without changing // the aliases for peek_under_roms, poke_under_roms etc diff --git a/c64/kernal/memory/vector_real.s b/c64/kernal/memory/vector_real.s index 5b3e4eff..1d5e379b 100644 --- a/c64/kernal/memory/vector_real.s +++ b/c64/kernal/memory/vector_real.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE vector_real: @@ -6,7 +9,7 @@ vector_real: // address originally used; after calling VECTOR and checking zero page // area afterwards, the address could be found there - // According to 'Compute's Mapping the Commodore 64' page 237, + // According to 'Computes Mapping the Commodore 64' page 237, // the CBM implementation does not disable IRQs - yet, the // 'C64 Programmers Reference Guide' does not contain such // warning and does not mention any preparations needed. diff --git a/c64/kernal/panic.s b/c64/kernal/panic.s index ef34736a..aa37b876 100644 --- a/c64/kernal/panic.s +++ b/c64/kernal/panic.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Something terrible happened - show the panic screen diff --git a/c64/kernal/print/print_features.s b/c64/kernal/print/print_features.s index 8c958a53..c4b4c0ae 100644 --- a/c64/kernal/print/print_features.s +++ b/c64/kernal/print/print_features.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print configured features on startup banner diff --git a/c64/kernal/print/print_hex_byte.s b/c64/kernal/print/print_hex_byte.s index d5d53760..5bcbbd34 100644 --- a/c64/kernal/print/print_hex_byte.s +++ b/c64/kernal/print/print_hex_byte.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print the hex value in .A as two digits @@ -17,7 +20,9 @@ print_hex_byte: lsr cmp #$0A adc #$30 + cld jsr JCHROUT + sed pla and #$0F cmp #$0A diff --git a/c64/kernal/print/print_kernal_message.s b/c64/kernal/print/print_kernal_message.s index 6e75e634..906ee939 100644 --- a/c64/kernal/print/print_kernal_message.s +++ b/c64/kernal/print/print_kernal_message.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print one of the standard Kernal messages, index in .X diff --git a/c64/kernal/print/print_pal_ntsc.s b/c64/kernal/print/print_pal_ntsc.s index ec4ae805..d005a63f 100644 --- a/c64/kernal/print/print_pal_ntsc.s +++ b/c64/kernal/print/print_pal_ntsc.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print video system on startup banner @@ -14,4 +17,4 @@ print_pal_ntsc: !: jmp print_kernal_message -#endif // CONFIG_SHOW_PAL_NTSC \ No newline at end of file +#endif // CONFIG_SHOW_PAL_NTSC diff --git a/c64/kernal/print/print_return.s b/c64/kernal/print/print_return.s index b53e8d6c..f9926e7d 100644 --- a/c64/kernal/print/print_return.s +++ b/c64/kernal/print/print_return.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print the carriage return diff --git a/c64/kernal/print/print_space.s b/c64/kernal/print/print_space.s index 48365891..374873f5 100644 --- a/c64/kernal/print/print_space.s +++ b/c64/kernal/print/print_space.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Print the space character diff --git a/c64/kernal/print/printf.s b/c64/kernal/print/printf.s index 44738e47..42934867 100644 --- a/c64/kernal/print/printf.s +++ b/c64/kernal/print/printf.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + // printf()-like routine for simplifying debugging // Prints the literal zero-terminated string that follows, @@ -140,4 +144,3 @@ printf_retreat: rts #endif // CONFIG_DBG_PRINTF - diff --git a/c64/kernal/rom_revision/ff80.kernal_revision.s b/c64/kernal/rom_revision/ff80.kernal_revision.s index 0aad2a67..74101501 100644 --- a/c64/kernal/rom_revision/ff80.kernal_revision.s +++ b/c64/kernal/rom_revision/ff80.kernal_revision.s @@ -1,8 +1,11 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // This byte (hex $FF80, dec 65408) identifies Kernal revision on several machines. Although not all // of the, used it for versioning purpose, here is the list of all the values I could find. Sources: -// - [CM64] Compute's Mapping the Commodore 64 (page 242/243) +// - [CM64] Computes Mapping the Commodore 64 (page 242/243) // - [MM] Marko Mäkelä article, http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c64/revisions.txt // - [VICE] Checked with ROMs included in VICE emulator // - [XEMU] Checked with ROMs retrieved by XEMU emulator @@ -59,5 +62,6 @@ // - $FF - Commander X16 (emulator r28) // + kernal_revision: .byte $F0 // chosen not to conflict with anything known so far diff --git a/c64/kernal/rs232/chkin_rs232_up2400.s b/c64/kernal/rs232/chkin_rs232_up2400.s index 0fb045b5..ea8edff1 100644 --- a/c64/kernal/rs232/chkin_rs232_up2400.s +++ b/c64/kernal/rs232/chkin_rs232_up2400.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CHKIN routine diff --git a/c64/kernal/rs232/chkin_rs232_up9600.s b/c64/kernal/rs232/chkin_rs232_up9600.s index 40d4e2ac..c1ffd6cb 100644 --- a/c64/kernal/rs232/chkin_rs232_up9600.s +++ b/c64/kernal/rs232/chkin_rs232_up9600.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CHKIN routine diff --git a/c64/kernal/rs232/chrin_rs232_up2400.s b/c64/kernal/rs232/chrin_rs232_up2400.s index 252cf2db..d11f6ca2 100644 --- a/c64/kernal/rs232/chrin_rs232_up2400.s +++ b/c64/kernal/rs232/chrin_rs232_up2400.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CHRIN routine diff --git a/c64/kernal/rs232/chrin_rs232_up9600.s b/c64/kernal/rs232/chrin_rs232_up9600.s index 0945111d..8ada792c 100644 --- a/c64/kernal/rs232/chrin_rs232_up9600.s +++ b/c64/kernal/rs232/chrin_rs232_up9600.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CHRIN routine diff --git a/c64/kernal/rs232/chrout_rs232.s b/c64/kernal/rs232/chrout_rs232.s index 9c3af02f..4ed361cf 100644 --- a/c64/kernal/rs232/chrout_rs232.s +++ b/c64/kernal/rs232/chrout_rs232.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CHROUT routine diff --git a/c64/kernal/rs232/ckout_rs232_up2400.s b/c64/kernal/rs232/ckout_rs232_up2400.s index 7cec81d6..40d1c374 100644 --- a/c64/kernal/rs232/ckout_rs232_up2400.s +++ b/c64/kernal/rs232/ckout_rs232_up2400.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CKOUT routine diff --git a/c64/kernal/rs232/ckout_rs232_up9600.s b/c64/kernal/rs232/ckout_rs232_up9600.s index e2877512..3e36affb 100644 --- a/c64/kernal/rs232/ckout_rs232_up9600.s +++ b/c64/kernal/rs232/ckout_rs232_up9600.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CKOUT routine diff --git a/c64/kernal/rs232/close_rs232.s b/c64/kernal/rs232/close_rs232.s index 52d4bf84..7a254c8d 100644 --- a/c64/kernal/rs232/close_rs232.s +++ b/c64/kernal/rs232/close_rs232.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the CLOSE routine diff --git a/c64/kernal/rs232/getin_rs232.s b/c64/kernal/rs232/getin_rs232.s index 17215ead..c1b01556 100644 --- a/c64/kernal/rs232/getin_rs232.s +++ b/c64/kernal/rs232/getin_rs232.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the GETIN routine diff --git a/c64/kernal/rs232/open_rs232.s b/c64/kernal/rs232/open_rs232.s index f4b1c0a0..06c08e65 100644 --- a/c64/kernal/rs232/open_rs232.s +++ b/c64/kernal/rs232/open_rs232.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RS-232 part of the OPEN routine diff --git a/c64/kernal/rs232/rs232_count_channels.s b/c64/kernal/rs232/rs232_count_channels.s index 7e032781..49379a81 100644 --- a/c64/kernal/rs232/rs232_count_channels.s +++ b/c64/kernal/rs232/rs232_count_channels.s @@ -1,26 +1,29 @@ - -// -// Sets .X to number of open RS-232 channels -// - - -#if HAS_RS232 - - -rs232_count_channels: - - ldx #$00 - ldy LDTND -!: - dey - bmi close_rs232_search_done - lda FAT, y - cmp #$02 - bne !- - inx - bpl !- // branch always - - rts - - -#endif +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Sets .X to number of open RS-232 channels +// + + +#if HAS_RS232 + + +rs232_count_channels: + + ldx #$00 + ldy LDTND +!: + dey + bmi close_rs232_search_done + lda FAT, y + cmp #$02 + bne !- + inx + bpl !- // branch always + + rts + + +#endif diff --git a/c64/kernal/rs232/up9600_disable.s b/c64/kernal/rs232/up9600_disable.s index 80ec3cc4..44d6691f 100644 --- a/c64/kernal/rs232/up9600_disable.s +++ b/c64/kernal/rs232/up9600_disable.s @@ -1,44 +1,46 @@ - -// -// Disable UP9600 interface -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_disable: // XXX adapt - - // XXX restore interrupt vectors and IRQ timer - - sei - lda CIA2_PRB // $DD01; DISABLE RTS - and #$FD - sta CIA2_PRB // $DD01 - lda #$7F - sta CIA2_ICR // $DD0D ; DISABLE ALL CIA INTERRUPTS - sta CIA1_ICR // $DC0D - lda #$41; QUICK (AND DIRTY) HACK TO SWITCH BACK - sta CIA1_TIMAHI // $DC05 ; TO THE DEFAULT CIA1 CONFIGURATION - lda #$81 - sta CIA1_ICR // $DC0D ; ENABLE TIMER1 (THIS IS DEFAULT) - lda #ORIGIRQ - sta IRQVECT+1 - lda #ORIGNMI - sta NMIVECT+1 - cli - pla - tay - pla - tax - pla - - - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Disable UP9600 interface +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_disable: // XXX adapt + + // XXX restore interrupt vectors and IRQ timer + + sei + lda CIA2_PRB // $DD01; DISABLE RTS + and #$FD + sta CIA2_PRB // $DD01 + lda #$7F + sta CIA2_ICR // $DD0D ; DISABLE ALL CIA INTERRUPTS + sta CIA1_ICR // $DC0D + lda #$41; QUICK (AND DIRTY) HACK TO SWITCH BACK + sta CIA1_TIMAHI // $DC05 ; TO THE DEFAULT CIA1 CONFIGURATION + lda #$81 + sta CIA1_ICR // $DC0D ; ENABLE TIMER1 (THIS IS DEFAULT) + lda #ORIGIRQ + sta IRQVECT+1 + lda #ORIGNMI + sta NMIVECT+1 + cli + pla + tay + pla + tax + pla + + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_enable.s b/c64/kernal/rs232/up9600_enable.s index f282588c..2f9be6db 100644 --- a/c64/kernal/rs232/up9600_enable.s +++ b/c64/kernal/rs232/up9600_enable.s @@ -1,133 +1,134 @@ - -// -// Enable UP9600 interface support -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_enable: // XXX adapt - - sei - - - - lda IRQVECT - cmp #ORIGIRQ - bne INSTERR; IRQ-VECTOR ALREADY CHANGED - lda NMIVECT - cmp #ORIGNMI - bne INSTERR; NMI-VECTOR ALREADY CHANGED - ldy #0 - sty RODBE - sty RODBS - sty RIDBE - sty RIDBS - ; PROBE FOR RS232 INTERFACE - cli - lda #$7F - sta CIA2_ICR // $DD0D ; DISABLE ALL NMIS - lda #$80 - sta CIA2_DDRB // $DD03 ; PB7 USED AS OUTPUT - sta $DD0E; STOP TIMERA - sta CIA2_CRB // $DD0F ; STOP TIMERB - bit CIA2_ICR // $DD0D ; CLEAR PENDING INTERRUPTS - ldx #8 -INSTALL2 - stx CIA2_PRB // $DD01; TOGGLE TXD - sta CIA2_PRB // $DD01; AND LOOK IF IT TRIGGERS AN - dex; SHIFT-REGISTER INTERRUPT - bne INSTALL2 - lda CIA2_ICR // $DD0D ; CHECK FOR BIT3 (SDR-FLAG) - and #8 - beq INSTERR; NO INTERFACE DETECTED - ; GENERATE LOOKUP TABLE - ldx #0 -INSTALL3 - stx OUTSTAT; OUTSTAT USED AS TEMPORARY VARIABLE - ldy #8 -INSTALL4 - asl OUTSTAT - ror - dey - bne INSTALL4 - sta REVTAB,X - inx - bpl INSTALL3 - - - - - - sei - // XXX set NEWIRQ as IRQ vector - // XXX set NMIDOBIT as NMI vector - - ldx TVSFLG; PAL OR NTSC VERSION PRINT - lda ILOTAB,X; (KEYSCAN INTERRUPT ONCE EVERY 1/64 SECOND) - sta CIA1_TIMBLO // $DC06 ; (SORRY THIS WILL BREAK CODE, THAT USES - lda IHITAB,X; THE TI$ - VARIABLE) - sta CIA1_TIMBHI // $DC07 ; START VALUE FOR TIMER B (OF CIA1) - txa - asl - eor #$33; ** TIME CONSTANT FOR SENDER ** - ldx #0; 51 OR 55 DEPENDING ON PAL/NTSC VERSION - sta CIA1_TIMALO // $DC04 ; START VALUE FOR TIMERA (OF CIA1) - stx CIA1_TIMAHI // $DC05 ; (TIME IS AROUND 1/(2*BAUDRATE) ) - asl; ** TIME CONSTANT FOR RECEIVER ** - ora #1; 103 OR 111 DEPENDING ON PAL/NTSC VERSION - sta CIA2_TIMBLO // $DD06 ; START VALUE FOR TIMERB (OF CIA2) - stx CIA2_TIMBHI // $DD07 ; (TIME IS AROUND 1/BAUDRATE ) - lda #$41; START TIMERA OF CIA1, SP1 USED AS OUTPUT - sta CIA1_CRA // $DC0E ; GENERATES THE SENDER'S BIT CLOCK - lda #1 - sta OUTSTAT - sta CIA1_ICR // $DC0D ; DISABLE TIMERA (CIA1) INTERRUPT - sta CIA1_CRB // $DC0F ; START TIMERB OF CIA1 (GENERATES KEYSCAN IRQ) - lda #$92; STOP TIMERB OF CIA2 (ENABLE SIGNAL AT PB7) - sta CIA2_CRB // $DD0F - lda #$98 - bit CIA2_ICR // $DD0D ; CLEAR PENDING NMIS - sta CIA2_ICR // $DD0D ; ENABLE NMI (SDR AND FLAG) (CIA2) - lda #$8A - sta CIA1_ICR // $DC0D ; ENABLE IRQ (TIMERB AND SDR) (CIA1) - lda #$FF - sta CIA2_PRB // $DD01; PB0-7 DEFAULT TO 1 - sta CIA1_SDR // $DC0C ; SP1 DEFAULTS TO 1 - sec - lda RIDBE - sbc RIDBS - cmp #200 - bcc ENABLE2;; DON'T ENABLE RTS IF REC-BUFFER IS FULL - lda #2;; ENABLE RTS - sta CIA2_DDRB // $DD03 ;; (THE RTS LINE IS THE ONLY OUTPUT) -ENABLE2 - cli - pla - tay - pla - tax - pla - rts - - - - -INSTERR - cli - sec - rts - - - - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Enable UP9600 interface support +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_enable: // XXX adapt + + sei + + + + lda IRQVECT + cmp #ORIGIRQ + bne INSTERR; IRQ-VECTOR ALREADY CHANGED + lda NMIVECT + cmp #ORIGNMI + bne INSTERR; NMI-VECTOR ALREADY CHANGED + ldy #0 + sty RODBE + sty RODBS + sty RIDBE + sty RIDBS + ; PROBE FOR RS232 INTERFACE + cli + lda #$7F + sta CIA2_ICR // $DD0D ; DISABLE ALL NMIS + lda #$80 + sta CIA2_DDRB // $DD03 ; PB7 USED AS OUTPUT + sta $DD0E; STOP TIMERA + sta CIA2_CRB // $DD0F ; STOP TIMERB + bit CIA2_ICR // $DD0D ; CLEAR PENDING INTERRUPTS + ldx #8 +INSTALL2 + stx CIA2_PRB // $DD01; TOGGLE TXD + sta CIA2_PRB // $DD01; AND LOOK IF IT TRIGGERS AN + dex; SHIFT-REGISTER INTERRUPT + bne INSTALL2 + lda CIA2_ICR // $DD0D ; CHECK FOR BIT3 (SDR-FLAG) + and #8 + beq INSTERR; NO INTERFACE DETECTED + ; GENERATE LOOKUP TABLE + ldx #0 +INSTALL3 + stx OUTSTAT; OUTSTAT USED AS TEMPORARY VARIABLE + ldy #8 +INSTALL4 + asl OUTSTAT + ror + dey + bne INSTALL4 + sta REVTAB,X + inx + bpl INSTALL3 + + + + + + sei + // XXX set NEWIRQ as IRQ vector + // XXX set NMIDOBIT as NMI vector + + ldx TVSFLG; PAL OR NTSC VERSION PRINT + lda ILOTAB,X; (KEYSCAN INTERRUPT ONCE EVERY 1/64 SECOND) + sta CIA1_TIMBLO // $DC06 ; (SORRY THIS WILL BREAK CODE, THAT USES + lda IHITAB,X; THE TI$ - VARIABLE) + sta CIA1_TIMBHI // $DC07 ; START VALUE FOR TIMER B (OF CIA1) + txa + asl + eor #$33; ** TIME CONSTANT FOR SENDER ** + ldx #0; 51 OR 55 DEPENDING ON PAL/NTSC VERSION + sta CIA1_TIMALO // $DC04 ; START VALUE FOR TIMERA (OF CIA1) + stx CIA1_TIMAHI // $DC05 ; (TIME IS AROUND 1/(2*BAUDRATE) ) + asl; ** TIME CONSTANT FOR RECEIVER ** + ora #1; 103 OR 111 DEPENDING ON PAL/NTSC VERSION + sta CIA2_TIMBLO // $DD06 ; START VALUE FOR TIMERB (OF CIA2) + stx CIA2_TIMBHI // $DD07 ; (TIME IS AROUND 1/BAUDRATE ) + lda #$41; START TIMERA OF CIA1, SP1 USED AS OUTPUT + sta CIA1_CRA // $DC0E ; GENERATES THE SENDER'S BIT CLOCK + lda #1 + sta OUTSTAT + sta CIA1_ICR // $DC0D ; DISABLE TIMERA (CIA1) INTERRUPT + sta CIA1_CRB // $DC0F ; START TIMERB OF CIA1 (GENERATES KEYSCAN IRQ) + lda #$92; STOP TIMERB OF CIA2 (ENABLE SIGNAL AT PB7) + sta CIA2_CRB // $DD0F + lda #$98 + bit CIA2_ICR // $DD0D ; CLEAR PENDING NMIS + sta CIA2_ICR // $DD0D ; ENABLE NMI (SDR AND FLAG) (CIA2) + lda #$8A + sta CIA1_ICR // $DC0D ; ENABLE IRQ (TIMERB AND SDR) (CIA1) + lda #$FF + sta CIA2_PRB // $DD01; PB0-7 DEFAULT TO 1 + sta CIA1_SDR // $DC0C ; SP1 DEFAULTS TO 1 + sec + lda RIDBE + sbc RIDBS + cmp #200 + bcc ENABLE2;; DON'T ENABLE RTS IF REC-BUFFER IS FULL + lda #2;; ENABLE RTS + sta CIA2_DDRB // $DD03 ;; (THE RTS LINE IS THE ONLY OUTPUT) +ENABLE2 + cli + pla + tay + pla + tax + pla + rts + + + + +INSTERR + cli + sec + rts + + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_ihitab.s b/c64/kernal/rs232/up9600_ihitab.s index 05310e40..43b53bd7 100644 --- a/c64/kernal/rs232/up9600_ihitab.s +++ b/c64/kernal/rs232/up9600_ihitab.s @@ -1,18 +1,21 @@ - -// -// Timer values for PAL/NTSC - high bytes -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_ihitab: - - .byte $42 - .byte $40 - - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Timer values for PAL/NTSC - high bytes +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_ihitab: + + .byte $42 + .byte $40 + + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_ilotab.s b/c64/kernal/rs232/up9600_ilotab.s index bede02ea..5492bedf 100644 --- a/c64/kernal/rs232/up9600_ilotab.s +++ b/c64/kernal/rs232/up9600_ilotab.s @@ -1,18 +1,21 @@ - -// -// Timer values for PAL/NTSC - low bytes -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_ilotab: - - .byte $95 - .byte $25 - - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Timer values for PAL/NTSC - low bytes +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_ilotab: + + .byte $95 + .byte $25 + + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_irq.s b/c64/kernal/rs232/up9600_irq.s index a5a99e0e..b7e0be2a 100644 --- a/c64/kernal/rs232/up9600_irq.s +++ b/c64/kernal/rs232/up9600_irq.s @@ -1,40 +1,43 @@ - -// -// RS-232 IRQ handler part -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_irq: - - lda CIA1_ICR // $DC0D - - lsr - lsr // move bit 1 (timer B flag) into Carry - and #$02 // test SDR (shift register) status - - beq up9600_irq_continue - - ldx RINONE - beq !+ // skip if not waiting for empty SDR - dex - stx RINONE -!: - bcc up9600_irq_end - -up9600_irq_continue: - - rts - -up9600_irq_end: - - pla - pla - jmp return_from_interrupt - - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// RS-232 IRQ handler part +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_irq: + + lda CIA1_ICR // $DC0D + + lsr + lsr // move bit 1 (timer B flag) into Carry + and #$02 // test SDR (shift register) status + + beq up9600_irq_continue + + ldx RINONE + beq !+ // skip if not waiting for empty SDR + dex + stx RINONE +!: + bcc up9600_irq_end + +up9600_irq_continue: + + rts + +up9600_irq_end: + + pla + pla + jmp return_from_interrupt + + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_nmi.s b/c64/kernal/rs232/up9600_nmi.s index fea3652d..ffe35c36 100644 --- a/c64/kernal/rs232/up9600_nmi.s +++ b/c64/kernal/rs232/up9600_nmi.s @@ -1,66 +1,69 @@ - -// -// RS-232 NMI handler part -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_nmi: - // XXX integrate with NMI handler - - pha - bit CIA2_ICR // $DD0D; check if CIA caused the interrupt - bpl NMIDOBI2; NO STARTBIT RECEIVED, THEN SKIP - lda #$13 - sta CIA2_CRB // $DD0F; START TIMER B (FORCED RELOAD, SIGNAL AT PB7) - sta CIA2_ICR // $DD0D; DISABLE TIMER AND FLAG INTERRUPTS - lda #NMIBYTRY - sta NMIVECT+1 -NMIDOBI2 - pla; IGNORE, IF NMI WAS TRIGGERED BY RESTORE-KEY - rti - ; -NMIBYTRY - pha - bit CIA2_ICR // $DD0D; CHECK BIT 7 (SDR FULL PRINT) - bpl NMIDOBI2; SDR NOT FULL, THEN SKIP (EG. RESTORE-KEY) - lda #$92 - sta CIA2_CRB // $DD0F; STOP TIMER B (KEEP SIGNALLING AT PB7!) - sta CIA2_ICR // $DD0D; ENABLE FLAG (AND TIMER) INTERRUPTS - lda #NMIDOBIT - sta NMIVECT+1 - phx_trash_a - phy_trash_a - lda CIA2_SDR // $DD0C; READ SDR (BIT0=DATABIT7,...,BIT7=DATABIT0) - cmp #128; MOVE BIT7 INTO CARRY-FLAG - and #127 - tax - lda REVTAB,X; READ DATABITS 1-7 FROM LOOKUP TABLE - adc #0; ADD DATABIT0 - ldy RIDBE; AND WRITE IT INTO THE RECEIVE BUFFER - sta (RIBUF),Y - iny - sty RIDBE - sec;;START BUFFER FULL CHK - tya - sbc RIDBS - cmp #200 - bcc NMIBYTR2 - lda CIA2_PRB // $DD01;; MORE THAN 200 BYTES IN THE RECEIVE BUFFER - and #$FD;; THEN DISABLE RTS - sta CIA2_PRB // $DD01 -NMIBYTR2 - ply_trash_a - plx_trash_a - pla - rti - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// RS-232 NMI handler part +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_nmi: + // XXX integrate with NMI handler + + pha + bit CIA2_ICR // $DD0D; check if CIA caused the interrupt + bpl NMIDOBI2; NO STARTBIT RECEIVED, THEN SKIP + lda #$13 + sta CIA2_CRB // $DD0F; START TIMER B (FORCED RELOAD, SIGNAL AT PB7) + sta CIA2_ICR // $DD0D; DISABLE TIMER AND FLAG INTERRUPTS + lda #NMIBYTRY + sta NMIVECT+1 +NMIDOBI2 + pla; IGNORE, IF NMI WAS TRIGGERED BY RESTORE-KEY + rti + ; +NMIBYTRY + pha + bit CIA2_ICR // $DD0D; CHECK BIT 7 (SDR FULL PRINT) + bpl NMIDOBI2; SDR NOT FULL, THEN SKIP (EG. RESTORE-KEY) + lda #$92 + sta CIA2_CRB // $DD0F; STOP TIMER B (KEEP SIGNALLING AT PB7!) + sta CIA2_ICR // $DD0D; ENABLE FLAG (AND TIMER) INTERRUPTS + lda #NMIDOBIT + sta NMIVECT+1 + phx_trash_a + phy_trash_a + lda CIA2_SDR // $DD0C; READ SDR (BIT0=DATABIT7,...,BIT7=DATABIT0) + cmp #128; MOVE BIT7 INTO CARRY-FLAG + and #127 + tax + lda REVTAB,X; READ DATABITS 1-7 FROM LOOKUP TABLE + adc #0; ADD DATABIT0 + ldy RIDBE; AND WRITE IT INTO THE RECEIVE BUFFER + sta (RIBUF),Y + iny + sty RIDBE + sec;;START BUFFER FULL CHK + tya + sbc RIDBS + cmp #200 + bcc NMIBYTR2 + lda CIA2_PRB // $DD01;; MORE THAN 200 BYTES IN THE RECEIVE BUFFER + and #$FD;; THEN DISABLE RTS + sta CIA2_PRB // $DD01 +NMIBYTR2 + ply_trash_a + plx_trash_a + pla + rti + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_rsin.s b/c64/kernal/rs232/up9600_rsin.s index 39009f0c..67cb5f93 100644 --- a/c64/kernal/rs232/up9600_rsin.s +++ b/c64/kernal/rs232/up9600_rsin.s @@ -1,43 +1,46 @@ - -// -// Get byte from serial interface -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_rsin: - - ldy RIDBS - cpy RIDBE - beq up9600_rsin_end; // skip (empty buffer, return with carry set) - - lda (RIBUF),Y - iny - sty RIDBS - pha // begin buffer emptying chk - tya - sec - sbc RIDBE - cmp #206 // 256-50 - bcc !+ - lda #$02 - ora CIA2_PR // $DD01 - sta CIA2_PR // enable RTS - clc - - // FALLTROUGH - -!: - pla - - // FALLTROUGH - -up9600_rsin_end: - - rts - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Get byte from serial interface +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_rsin: + + ldy RIDBS + cpy RIDBE + beq up9600_rsin_end; // skip (empty buffer, return with carry set) + + lda (RIBUF),Y + iny + sty RIDBS + pha // begin buffer emptying chk + tya + sec + sbc RIDBE + cmp #206 // 256-50 + bcc !+ + lda #$02 + ora CIA2_PR // $DD01 + sta CIA2_PR // enable RTS + clc + + // FALLTROUGH + +!: + pla + + // FALLTROUGH + +up9600_rsin_end: + + rts + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/rs232/up9600_rsout.s b/c64/kernal/rs232/up9600_rsout.s index fd4e607d..0efed7f4 100644 --- a/c64/kernal/rs232/up9600_rsout.s +++ b/c64/kernal/rs232/up9600_rsout.s @@ -1,56 +1,59 @@ - -// -// Put byte to serial interface -// - -// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations - - -#if CONFIG_RS232_UP9600 - - -up9600_rsout: - - pha - sta $9E // XXX synchronize with aliases - cmp #$80 - and #$7F - stx $A8 // XXX synchronize with aliases - sty $A7 // XXX synchronize with aliases - tax - jsr up9600_rsout_time - - lda REVTAB, x - adc #$00 - lsr - sei - sta CIA1_SDR // $DC0C - lda #$02 - STA XXX_OUTSTAT - ror - ora #$7F - sta CIA1_SDR // $DC0C - cli - ldx $A8 // XXX synchronize with aliases - ldy $A7 // XXX synchronize with aliases - pla - rts - -up9600_rsout_time: - - cli - lda #$FD - sta TIME+2 // XXX check if this is the lowest byte - -rs232_rsout_wait: - - lda XXX_OUTSTAT - beq !+ - bit TIME+2 - bmi up9600_rsout_wait - -!: - jmp $F490 // XXX - - -#endif // CONFIG_RS232_UP9600 +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Put byte to serial interface +// + +// Based on UP9600 code by Daniel Dallman with Bo Zimmerman adaptations + + +#if CONFIG_RS232_UP9600 + + +up9600_rsout: + + pha + sta $9E // XXX synchronize with aliases + cmp #$80 + and #$7F + stx $A8 // XXX synchronize with aliases + sty $A7 // XXX synchronize with aliases + tax + jsr up9600_rsout_time + + lda REVTAB, x + adc #$00 + lsr + sei + sta CIA1_SDR // $DC0C + lda #$02 + STA XXX_OUTSTAT + ror + ora #$7F + sta CIA1_SDR // $DC0C + cli + ldx $A8 // XXX synchronize with aliases + ldy $A7 // XXX synchronize with aliases + pla + rts + +up9600_rsout_time: + + cli + lda #$FD + sta TIME+2 // XXX check if this is the lowest byte + +rs232_rsout_wait: + + lda XXX_OUTSTAT + beq !+ + bit TIME+2 + bmi up9600_rsout_wait + +!: + jmp $F490 // XXX + + +#endif // CONFIG_RS232_UP9600 diff --git a/c64/kernal/screen/chrout_screen.s b/c64/kernal/screen/chrout_screen.s index 0b447fad..356816d0 100644 --- a/c64/kernal/screen/chrout_screen.s +++ b/c64/kernal/screen/chrout_screen.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // CHROUT routine - screen support (character output) @@ -29,12 +32,12 @@ chrout_screen: bcc !+ and #$7F - jmp output_literal_char // not high char + jmp chrout_screen_literal // not high char !: // Range $20-$3F is unchanged cmp #$40 - bcc output_literal_char // not high char + bcc chrout_screen_literal // not high char // Unshifted letters and symbols from $40-$5F // all end up being -$40 @@ -49,63 +52,77 @@ chrout_screen: // Fix shifted chars by adding $20 again cmp #$20 - bcc output_literal_char // not high char + bcc chrout_screen_literal // not high char cmp #$40 - bcs output_literal_char // not high char + bcs chrout_screen_literal // not high char clc adc #$20 -output_literal_char: - + // FALLTROUGH + +chrout_screen_literal: + // Write normal character on the screen - pha - - ldy PNTR - ora RVS // Compute's Mapping the 64 p38 + tax // store screen code, we need .A for calculations + + // First we need offset from PNT in .Y, we can take it from PNTR + + jsr screen_get_clipped_PNTR + + // Put the character on the screen + + txa + ora RVS // Computes Mapping the 64, page 38 sta (PNT),y // Decrement number of chars waiting to be inserted + lda INSRT beq !+ dec INSRT !: - pla + // Toggle quote flag if required + + txa cmp #$22 - bne not_quote + bne !+ - // Toggle quote flag if required lda QTSW eor #$80 sta QTSW +!: + // Set colour of the newly printed character -not_quote: - - // Set colour lda COLOR sta (USER),y - // Advance the column, and scroll screen down if we need - // to insert a 2nd line in this logical line. - // (eg Compute's Mapping the 64 p41) - ldx TBLX + // Advance the column + + ldy PNTR iny sty PNTR + + // Scroll down (extend logical line) if needed + cpy #40 bne !+ jsr screen_grow_logical_line + inc TBLX ldy PNTR !: - cpy #80 - bcc chrout_screen_done - lda #0 - sta PNTR - jmp chrout_screen_advance_to_next_line + // If not the 80th character of the logical row, we are done + cpy #80 + bcc chrout_screen_calc_lptr_done + + // Advance to the next line + + jmp screen_advance_to_next_line chrout_screen_calc_lptr_done: - jsr screen_calculate_line_pointer + jsr screen_calculate_pointers // FALLTROUGH diff --git a/c64/kernal/screen/chrout_screen_advance_to_next_line.s b/c64/kernal/screen/chrout_screen_advance_to_next_line.s deleted file mode 100644 index 323c47e8..00000000 --- a/c64/kernal/screen/chrout_screen_advance_to_next_line.s +++ /dev/null @@ -1,44 +0,0 @@ - -chrout_screen_advance_to_next_line: - - // Go to start of line - lda #0 - sta PNTR - // Advance line number - ldy TBLX - - // Do quick fix to line pointer to work out if it is off - // the bottom of the screen. - ldx #40 - lda LDTBL,y - bmi !+ - .byte $2c -!: ldx #80 - txa - clc - adc PNT+0 - sta PNT+0 - lda PNT+1 - adc #0 - sta PNT+1 - - inc TBLX - - // Check if it will trigger scrolling - // Work out if we have gone off the bottom of the screen? - // 1040 > 1024, so if high byte of screen pointer is >= (HIBASE+4), - // then we are off the bottom of the screen - lda PNT+1 - sec - sbc HIBASE - cmp #3 - bcc !+ - lda PNT+0 - cmp #$e7 - bcc !+ - - // Off the bottom of the screen - jsr scroll_screen_up -!: - - jmp chrout_screen_calc_lptr_done diff --git a/c64/kernal/screen/chrout_screen_clr.s b/c64/kernal/screen/chrout_screen_clr.s index ab9469dd..7da09ca6 100644 --- a/c64/kernal/screen/chrout_screen_clr.s +++ b/c64/kernal/screen/chrout_screen_clr.s @@ -1,9 +1,13 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // CLR key handling within CHROUT // + chrout_screen_CLR: jsr clear_screen - jmp chrout_screen_done + jmp chrout_screen_calc_lptr_done diff --git a/c64/kernal/screen/chrout_screen_control.s b/c64/kernal/screen/chrout_screen_control.s index 05f5f828..7f93c521 100644 --- a/c64/kernal/screen/chrout_screen_control.s +++ b/c64/kernal/screen/chrout_screen_control.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // CHROUT routine - screen support, control codes diff --git a/c64/kernal/screen/chrout_screen_crsr.s b/c64/kernal/screen/chrout_screen_crsr.s index ed174568..cb276f41 100644 --- a/c64/kernal/screen/chrout_screen_crsr.s +++ b/c64/kernal/screen/chrout_screen_crsr.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Cursor keys handling within CHROUT @@ -6,38 +9,50 @@ chrout_screen_CRSR_UP: - lda PNTR - sec - sbc #40 - sta PNTR + lda TBLX + beq chrout_screen_CRSR_done + dec TBLX + + // FALLTROUGH + +chrout_screen_CRSR_done: + jmp chrout_screen_calc_lptr_done chrout_screen_CRSR_DOWN: - lda PNTR - clc - adc #40 - sta PNTR - // We need to advance the pointer manually, as normalising - // now will break things. The pointer update is required - // so that we can tell if we really are on the bottom phys - // screen line or not - jsr screen_scroll_up_if_on_last_line - jmp chrout_screen_calc_lptr_done - - -chrout_screen_CRSR_LEFT: - lda TBLX - ora PNTR - beq !+ // top-left corner, recalculating pointer is not necessary, but this is a very rare case nevertheless - dec PNTR + cmp #24 + bne !+ + jsr screen_scroll_up !: + inc TBLX jmp chrout_screen_calc_lptr_done chrout_screen_CRSR_RIGHT: - inc PNTR - jmp chrout_screen_calc_lptr_done + jsr screen_get_clipped_PNTR + cpy #39 + beq_16 screen_advance_to_next_line + + iny +!: + sty PNTR + bpl chrout_screen_CRSR_done // branch always + + +chrout_screen_CRSR_LEFT: + + jsr screen_get_clipped_PNTR + dey + bpl !- + + lda TBLX + beq chrout_screen_CRSR_done + + dec TBLX + lda #39 + sta PNTR + bne chrout_screen_CRSR_done // branch always diff --git a/c64/kernal/screen/chrout_screen_del.s b/c64/kernal/screen/chrout_screen_del.s index 88a403b2..5cfaaa07 100644 --- a/c64/kernal/screen/chrout_screen_del.s +++ b/c64/kernal/screen/chrout_screen_del.s @@ -1,8 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // CHROUT routine - screen support, DEL key handling // + chrout_screen_DEL: // In insert mode it embeds control character @@ -10,56 +14,107 @@ chrout_screen_DEL: beq !+ jmp chrout_screen_quote !: - ldx PNTR - bne chrout_screen_del_column_non_0 + ldy PNTR + beq chrout_screen_del_column_0 + cpy #40 + bne chrout_screen_del_column_normal // FALLTROUGH -chrout_screen_del_column_0: +chrout_screen_del_column_40: - ldy TBLX - beq chrout_screen_del_done // delete from row 0, col 0 does nothing + // First column of the extended line - decrement USER/PNT for copying - // Column 0 delete just moves us to the end of the - // previous line, without actually deleting anything +#if HAS_OPCODES_65CE02 + dew USER + dew PNT +#else + lda USER+0 + bne !+ + dec USER+1 + dec PNT+1 +!: + dec USER+0 + dec PNT+0 +#endif - dec TBLX - jsr screen_get_current_line_logical_length - lda LNMX - sta PNTR + // Copy characters + ldx #39 + ldy #0 - jmp chrout_screen_calc_lptr_done + jsr chrout_screen_del_copy_loop -chrout_screen_del_column_non_0: + // Finish by moving the cursor left + jmp chrout_screen_CRSR_LEFT - // Copy rest of line down - jsr screen_get_current_line_logical_length +chrout_screen_del_column_normal: + + // We need to scroll back the rest of the logical line + + // First reduce PNTR to 0-39 range + jsr screen_get_clipped_PNTR + sty PNTR + + // Now get the offset to the last logical line character + jsr screen_get_logical_line_end_ptr + tya + + // Substract the PNTR value, this will tell us how many characters we need to move + sec + sbc PNTR + tax + + // Perform the character copy (scroll back) in a loop ldy PNTR - cpy LNMX - beq !++ dey -!: - iny - lda (PNT),y - dey - sta (PNT),y - iny - lda (USER),y - dey - sta (USER),y - iny - cpy LNMX - bne !- + jsr chrout_screen_del_copy_loop - // Clear char at end of line - jsr screen_get_current_line_logical_length - tay - lda #$20 - sta (PNT),y -!: dec PNTR // FALLTROUGH chrout_screen_del_done: - jmp chrout_screen_done + + jmp chrout_screen_calc_lptr_done + +chrout_screen_del_copy_loop: + + iny + lda (USER),y + dey + sta (USER),y + iny + lda (PNT),y + dey + sta (PNT),y + iny + + dex + bpl chrout_screen_del_copy_loop + + // Clear char at end of line (just the character - not color!) + lda #$20 + sta (PNT),y + + rts + +chrout_screen_del_column_0: + + ldy TBLX + beq chrout_screen_del_done // delete from row 0, col 0 does nothing + + // Move cursor to end of previous line + dec TBLX + lda #39 + sta PNTR + + // Update PNT and USER pointers + jsr screen_calculate_PNT_USER + + // Put space character at the current cursor position (do not clear the color!) + ldy #39 + lda #$20 + sta (PNT),y + + // Finish with recalculating all the variables + bne chrout_screen_del_done diff --git a/c64/kernal/screen/chrout_screen_gfxtxt.s b/c64/kernal/screen/chrout_screen_gfxtxt.s index e523e03b..9f326e43 100644 --- a/c64/kernal/screen/chrout_screen_gfxtxt.s +++ b/c64/kernal/screen/chrout_screen_gfxtxt.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // GFX/TXT mode switch handling within CHROUT diff --git a/c64/kernal/screen/chrout_screen_home.s b/c64/kernal/screen/chrout_screen_home.s index 77976bd0..4f0e3d05 100644 --- a/c64/kernal/screen/chrout_screen_home.s +++ b/c64/kernal/screen/chrout_screen_home.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // HOME key handling within CHROUT @@ -7,4 +10,4 @@ chrout_screen_HOME: jsr cursor_home - jmp chrout_screen_done + jmp chrout_screen_calc_lptr_done diff --git a/c64/kernal/screen/chrout_screen_ins.s b/c64/kernal/screen/chrout_screen_ins.s index 3082012a..74be6b2a 100644 --- a/c64/kernal/screen/chrout_screen_ins.s +++ b/c64/kernal/screen/chrout_screen_ins.s @@ -1,45 +1,80 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // CHROUT routine - screen support, INS key handling // + chrout_screen_INS: - // Insert (shift-DELETE) + // First check if last character of the logical line is space - // Abort if line already max length, ie 79th char is not a space - jsr screen_get_current_line_logical_length - cmp #79 - bne !+ - tay - lda (PNT),y - cmp #$20 - beq !+ + jsr screen_check_space_ends_line + beq chrout_screen_ins_possible - // Line is too long to extend - jmp chrout_screen_done + // Not space, we cannot insert anything -!: - // Work out if line needs to be expanded, and if so expand it - ldy #39 - lda (PNT),y - cmp #$20 - beq !+ + bne_16 chrout_screen_done +chrout_screen_ins_possible: + + // Move chars towards end of the line + jsr screen_get_logical_line_end_ptr + + // Special handling for cursor in second line + ldx TBLX + lda LDTBL+0, x + bpl chrout_screen_ins_second_line + + // Perform character copy + jsr chrout_screen_ins_copy_loop + + // Put space in the inserted gap + lda #$20 + sta (PNT), y + + // If line does not end with space now, try to grow the logical line + + jsr screen_check_space_ends_line + beq chrout_screen_ins_done jsr screen_grow_logical_line - -!: - // Shuffle chars towards end of line - jsr screen_get_current_line_logical_length - tay -!: + + // FALLTROUGH + +chrout_screen_ins_done: + + // End of processing + jmp chrout_screen_calc_lptr_done + +chrout_screen_ins_second_line: + + // Adapt PNTR for copying + lda PNTR + sec + sbc #40 + sta PNTR + + // Perform character copy + jsr chrout_screen_ins_copy_loop + + // Put space in the inserted gap + lda #$20 + sta (PNT), y + + // End of processing + bne chrout_screen_ins_done // branch always + +chrout_screen_ins_copy_loop: + // Note: While the following routine is obvious to any skilled // in the art as the most obvious simple and efficient solution, // if the screen writes are before the colour writes, it results // in a relatively long verbatim stretch of bytes when compared to // the C64 KERNAL. Thus we have swapped the order, just to reduce // the potential for any argument of copyright infringement, even - // though we really don't believe that the routine can be copyrighted + // though we really do not believe that the routine can be copyrighted // due to the lack of creativity. dey lda (USER),y @@ -52,13 +87,10 @@ chrout_screen_INS: dey cpy PNTR - bne !- + bne chrout_screen_ins_copy_loop // Increase insert mode count (which causes quote-mode like behaviour) inc INSRT - // Put space in the inserted gap - lda #$20 - sta (PNT),y - - jmp chrout_screen_done + // Return from loop + rts diff --git a/c64/kernal/screen/chrout_screen_jumptable_codes.s b/c64/kernal/screen/chrout_screen_jumptable_codes.s index 321309bc..4e494b4d 100644 --- a/c64/kernal/screen/chrout_screen_jumptable_codes.s +++ b/c64/kernal/screen/chrout_screen_jumptable_codes.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Jumptable for screen control codes support. To improve performance, should be sorted @@ -90,6 +93,8 @@ chrout_screen_jumptable_hi: #else +.if (mod(*, $2) == 1) { nop } // align code so that vector never crosses page boundary + chrout_screen_jumptable: .word chrout_screen_CLR @@ -115,4 +120,6 @@ chrout_screen_jumptable: .word chrout_screen_DEL .word chrout_screen_RETURN +.if (mod(*, $2) == 0) { nop } // make sure routine size is always the same, needed by build system + #endif diff --git a/c64/kernal/screen/chrout_screen_quote.s b/c64/kernal/screen/chrout_screen_quote.s index 266f6d36..8bbe2440 100644 --- a/c64/kernal/screen/chrout_screen_quote.s +++ b/c64/kernal/screen/chrout_screen_quote.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // CHROUT routine - screen support, control codes in quote mode @@ -17,4 +20,4 @@ chrout_screen_quote: bcc !+ adc #$BF // C=1, so adding $BF + C = add $C0 !: - jmp output_literal_char + jmp chrout_screen_literal diff --git a/c64/kernal/screen/chrout_screen_return.s b/c64/kernal/screen/chrout_screen_return.s index 521c5323..4148dda6 100644 --- a/c64/kernal/screen/chrout_screen_return.s +++ b/c64/kernal/screen/chrout_screen_return.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RETURN key handling within CHROUT @@ -7,8 +10,23 @@ chrout_screen_RETURN: // RETURN clears quote and insert modes, it also clears reverse flag + lda #$00 sta QTSW sta INSRT sta RVS - jmp chrout_screen_advance_to_next_line + + // RETURN key moves cursor two lines down in case + // of first line of the extended logical line + + ldy TBLX + cpy #24 + beq !+ // last line on screen - no need for a double line skip + + lda LDTBL+1, y + bmi !+ // current line is not continued + + inc TBLX + jsr screen_calculate_PNT_USER +!: + jmp screen_advance_to_next_line diff --git a/c64/kernal/screen/chrout_screen_rvs.s b/c64/kernal/screen/chrout_screen_rvs.s index b1f68b76..3cb679ae 100644 --- a/c64/kernal/screen/chrout_screen_rvs.s +++ b/c64/kernal/screen/chrout_screen_rvs.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // RVS ON/OFF handling within CHROUT diff --git a/c64/kernal/screen/chrout_screen_shift_onoff.s b/c64/kernal/screen/chrout_screen_shift_onoff.s index 8f16587d..7ecbbe2a 100644 --- a/c64/kernal/screen/chrout_screen_shift_onoff.s +++ b/c64/kernal/screen/chrout_screen_shift_onoff.s @@ -1,8 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // SHIFT ON/OFF handling within CHROUT // + chrout_screen_SHIFT_ON: lda #$00 // enable SHIFT+VENDOR combination diff --git a/c64/kernal/screen/chrout_screen_stop.s b/c64/kernal/screen/chrout_screen_stop.s index 179c217f..3c638032 100644 --- a/c64/kernal/screen/chrout_screen_stop.s +++ b/c64/kernal/screen/chrout_screen_stop.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // STOP key handling within CHROUT diff --git a/c64/kernal/screen/chrout_screen_tab.s b/c64/kernal/screen/chrout_screen_tab.s index ac48295c..13634dc9 100644 --- a/c64/kernal/screen/chrout_screen_tab.s +++ b/c64/kernal/screen/chrout_screen_tab.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tabulation keys handling within CHROUT @@ -9,21 +12,27 @@ chrout_screen_TAB_FW: - lda PNTR + jsr screen_get_clipped_PNTR + tya ora #%00000111 - sta PNTR - inc PNTR + tay + iny + cpy #40 + bcc !+ + ldy #39 +!: + sty PNTR + jmp chrout_screen_calc_lptr_done chrout_screen_TAB_BW: - lda TBLX - ora PNTR - beq !+ // top-left corner, recalculating pointer is not necessary, but this is a very rare case nevertheless + jsr screen_get_clipped_PNTR + beq !+ // column 0, recalculating pointers is not necessary, but this is a rare case nevertheless - dec PNTR - lda PNTR + dey + tya and #%11111000 sta PNTR !: diff --git a/c64/kernal/screen/clear_screen_real.s b/c64/kernal/screen/clear_screen_real.s deleted file mode 100644 index df0b835a..00000000 --- a/c64/kernal/screen/clear_screen_real.s +++ /dev/null @@ -1,62 +0,0 @@ -// Clear screen and initialise line link table -// (Compute's Mapping the 64 p215-216) - -clear_screen_real: - - // XXX it is probably a good idea to hide cursor first - - // Clear line link table - // (Compute's Mapping the 64 p215) - - lda #$00 - ldy #24 -clearscreen_l1: - sta LDTBL,y - dey - bpl clearscreen_l1 - - // Y now = #$FF - - // Clear screen RAM. - // We should do this at HIBASE, which annoyingly - // is no ZP, so we need to make a vector - // (Compute's Mapping the 64 p216) - // Get pointer to the screen into PNT - // as it is the first appropriate place for it found when - // searching through the ZP allocations listed in - // Compute's Mapping the 64 - sta PNT+0 - lda HIBASE - sta PNT+1 - ldx #$03 // countdown for pages to update - iny // Y now = #$00 - lda #$20 // space character -clearscreen_l2: - sta (PNT),y - iny - bne clearscreen_l2 - // To draw only 1000 bytes, add 250 to address each time - lda PNT - clc - adc #<250 - sta PNT - lda PNT+1 - adc #>250 - sta PNT+1 - lda #$20 // get space character again - dex - bpl clearscreen_l2 - - // Clear colour RAM - // (Compute's Mapping the 64 p216) - lda COLOR -clearscreen_l3: - sta $d800,y - sta $d900,y - sta $da00,y - sta $db00-24,y // so we only erase 1000 bytes - iny - bne clearscreen_l3 - - // (Compute's Mapping the 64 p216) - jmp cursor_home diff --git a/c64/kernal/screen/cursor.s b/c64/kernal/screen/cursor.s index 0221cf18..15b460d2 100644 --- a/c64/kernal/screen/cursor.s +++ b/c64/kernal/screen/cursor.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Variables used: @@ -28,9 +31,8 @@ cursor_blink: // FALLTROUGH cursor_draw: - jsr screen_calculate_line_pointer // XXX try to make this call not needed - ldy PNTR + jsr screen_get_clipped_PNTR lda (PNT),y sta GDBLN eor #$80 @@ -58,8 +60,8 @@ cursor_hide_if_visible: cursor_undraw: + jsr screen_get_clipped_PNTR lda GDBLN - ldy PNTR sta (PNT),y lda GDCOL sta (USER),y diff --git a/c64/kernal/screen/cursor_enable.s b/c64/kernal/screen/cursor_enable.s index 72646312..155f28b4 100644 --- a/c64/kernal/screen/cursor_enable.s +++ b/c64/kernal/screen/cursor_enable.s @@ -1,10 +1,15 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Variables used: // - BLNSW (cursor blink switch) // + cursor_enable: + lda #$00 sta BLNSW rts diff --git a/c64/kernal/screen/cursor_home.s b/c64/kernal/screen/cursor_home.s deleted file mode 100644 index bb9d9bd2..00000000 --- a/c64/kernal/screen/cursor_home.s +++ /dev/null @@ -1,12 +0,0 @@ - -// -// Home the cursor (Compute's Mapping the 64 p216) -// - -cursor_home: - - lda #$00 - sta PNTR // x position - sta TBLX // y position - - jmp screen_calculate_line_pointer diff --git a/c64/kernal/screen/cursor_show.s b/c64/kernal/screen/cursor_show.s index c21b092c..e96987aa 100644 --- a/c64/kernal/screen/cursor_show.s +++ b/c64/kernal/screen/cursor_show.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Variables used: @@ -6,6 +9,7 @@ // - BLNCT (cursor blink countdown) // + cursor_show_if_enabled: lda BLNSW bne cursor_show_end diff --git a/c64/kernal/screen/e50a.plot.s b/c64/kernal/screen/e50a.plot.s index a36dfc08..e42d76c0 100644 --- a/c64/kernal/screen/e50a.plot.s +++ b/c64/kernal/screen/e50a.plot.s @@ -1,14 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 290 -// - [CM64] Compute's Mapping the Commodore 64 - page 215 +// - [RG64] C64 Programmers Reference Guide - page 290 +// - [CM64] Computes Mapping the Commodore 64 - page 215 // // CPU registers that has to be preserved (see [RG64]): none // + PLOT: + bcs plot_get // Note: the 'set' part has to start from $E50C, as this is a known address @@ -21,7 +26,7 @@ plot_set: sty PNTR stx TBLX - jsr screen_calculate_line_pointer + jsr screen_calculate_pointers // FALLTROUGH to save one byte on RTS diff --git a/c64/kernal/screen/e544.clear_screen.jmp.s b/c64/kernal/screen/e544.clear_screen.jmp.s deleted file mode 100644 index 50d16f38..00000000 --- a/c64/kernal/screen/e544.clear_screen.jmp.s +++ /dev/null @@ -1,6 +0,0 @@ -// Clear screen and initialise line link table -// (Compute's Mapping the 64 p215-216) - -clear_screen: - - jmp clear_screen_real diff --git a/c64/kernal/screen/e544.clear_screen.s b/c64/kernal/screen/e544.clear_screen.s new file mode 100644 index 00000000..e80029ca --- /dev/null +++ b/c64/kernal/screen/e544.clear_screen.s @@ -0,0 +1,33 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Clear screen and initialise line link table, described in: +// +// - [CM64] Computes Mapping the Commodore 64 - pages 215-216 +// + + +clear_screen: + + // Clear the line link table - cheecked on original ROMs, + // the highest bit set means that the line is NOT a logical + // continuation of the previous one + + lda #$80 + ldy #24 +!: + sta LDTBL,y + dey + bpl !- + + // Clear all the rows + ldx #24 +!: + jsr screen_clear_line + dex + bpl !- + + // Fall to cursor home routine + jmp cursor_home diff --git a/c64/kernal/screen/e566.cursor_home.s b/c64/kernal/screen/e566.cursor_home.s new file mode 100644 index 00000000..0e22fe78 --- /dev/null +++ b/c64/kernal/screen/e566.cursor_home.s @@ -0,0 +1,18 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Home the cursor, described in: +// +// - [CM64] Computes Mapping the Commodore 64 - page 216 +// + + +cursor_home: + + lda #$00 + sta PNTR // current column (logical) + sta TBLX // current row + + // FALLTROUGH to the next routine diff --git a/c64/kernal/,stubs/e566.interop b/c64/kernal/screen/e566.interop similarity index 100% rename from c64/kernal/,stubs/e566.interop rename to c64/kernal/screen/e566.interop diff --git a/c64/kernal/screen/e56c.interop b/c64/kernal/screen/e56c.interop new file mode 100644 index 00000000..6281847b --- /dev/null +++ b/c64/kernal/screen/e56c.interop @@ -0,0 +1,4 @@ + +This is a well-known address, probably used by lots of software. See for example here: + +- https://www.lemon64.com/forum/viewtopic.php?t=69526&sid=836d087e9759db667ba3bb1732eea266 diff --git a/c64/kernal/screen/e56c.screen_calculate_pointers.s b/c64/kernal/screen/e56c.screen_calculate_pointers.s new file mode 100644 index 00000000..591862c6 --- /dev/null +++ b/c64/kernal/screen/e56c.screen_calculate_pointers.s @@ -0,0 +1,18 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Set pointer (PNT) to current screen line , described in: +// +// - [CM64] Computes Mapping the Commodore 64 - page 216 +// - http://sta.c64.org/cbm64scrfunc.html +// + +// XXX find out what the original ROM really recalculate + + +screen_calculate_pointers: + + jsr screen_calculate_PNT_USER + jmp screen_calculate_PNTR_LNMX diff --git a/c64/kernal/,stubs/e8ea.interop b/c64/kernal/screen/e8ea.interop similarity index 100% rename from c64/kernal/,stubs/e8ea.interop rename to c64/kernal/screen/e8ea.interop diff --git a/c64/kernal/screen/e8ea.screen_scroll_up.s b/c64/kernal/screen/e8ea.screen_scroll_up.s new file mode 100644 index 00000000..fb3f262e --- /dev/null +++ b/c64/kernal/screen/e8ea.screen_scroll_up.s @@ -0,0 +1,133 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Scroll the whole screen up by 1 logical line, described in: +// +// - [CM64] Computes Mapping the Commodore 64 - page 218 +// + + +screen_scroll_up: + + // First handle CTRL and NO_SCRL keys + +#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 + + // Do not scroll if NO_SCRL is pressed and interrupts are enabled +!: + php + pla + and #%00000010 + bne !+ // branch if IRQs disabled, we cannot detect NO_SCRL status + + lda SHFLAG + and #KEY_FLAG_NO_SCRL + bne !- +!: + +#endif + + // Check if CTRL key pressed - if so, perform a delay + + lda SHFLAG + and #KEY_FLAG_CTRL + beq screen_scroll_up_delay_done + + ldy #$09 +!: + ldx #$FF + jsr wait_x_bars + dey + bne !- + + // FALLTROUGH + +screen_scroll_up_delay_done: // entry point for cursor move control codes + + // Scroll the LDTBL (line link table) + + ldy #$00 +!: + lda LDTBL+1, y + sta LDTBL+0, y + iny + cpy #24 + bne !- + + lda #$80 + sta LDTBL+24 + + // Preserve SAL and EAL, prepare initial SAL/EAL/PNT/USER values + + jsr screen_preserve_sal_eal + + lda HIBASE + sta SAL+1 + sta EAL+1 + + lda #>$D800 + sta PNT+1 + sta USER+1 + + lda #$00 + sta EAL+0 + sta USER+0 + lda #40 + sta SAL+0 + sta PNT+0 + + // Now copy, SAL->EAL, PNT->USER, in a loop + + ldy #$00 + +screen_scroll_up_loop: + + lda (SAL), y + sta (EAL), y + lda (PNT), y + sta (USER), y + + // Check if this was the last byte (last destination byte for color copy is #DBBF) + + cpy #$BF + bne !+ // definitely not the last byte + lda USER+1 + cmp #$DB + beq screen_scroll_up_loop_done +!: + // Increment .Y, possibly advance pointers + + iny + bne screen_scroll_up_loop + + inc SAL+1 + inc EAL+1 + inc USER+1 + inc PNT+1 + bne screen_scroll_up_loop // branch alwayys + +screen_scroll_up_loop_done: + + // Restore SAL and EAL + + jsr screen_restore_sal_eal + + // Clear the newly introduced line + + ldx #24 + jsr screen_clear_line + + // Decrement the current physical line number + + dec TBLX + + // If the first line is linked, scroll once more + + bit LDTBL+0 + bpl screen_scroll_up + + // Recalculate PNT and USER + + jmp screen_calculate_PNT_USER diff --git a/c64/kernal/,stubs/e9ff.interop b/c64/kernal/screen/e9ff.interop similarity index 100% rename from c64/kernal/,stubs/e9ff.interop rename to c64/kernal/screen/e9ff.interop diff --git a/c64/kernal/screen/e9ff.screen_clear_line.s b/c64/kernal/screen/e9ff.screen_clear_line.s new file mode 100644 index 00000000..6dc1f915 --- /dev/null +++ b/c64/kernal/screen/e9ff.screen_clear_line.s @@ -0,0 +1,37 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Well-known routine, described in: +// +// - [CM64] Computes Mapping the Commodore 64 - page 219 +// - http://sta.c64.org/cbm64scrfunc.html +// +// input: .X - screen line to clear +// +// Checked that original routine preserves X (convenient for loops), +// and leaves space screen code in .A, so duplicate this behaviour +// + + +screen_clear_line: + + // First, calculate PNT and USER + phx_trash_a + jsr screen_calculate_PNT_USER_from_X + plx_trash_a + + // Now clear the line + ldy #39 +!: + lda COLOR + sta (USER), y + lda #$20 // space character screen code + sta (PNT), y + + dey + bpl !- + + // Done + rts diff --git a/c64/kernal/screen/screen.s b/c64/kernal/screen/screen.s index 6964d141..2d3611df 100644 --- a/c64/kernal/screen/screen.s +++ b/c64/kernal/screen/screen.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: @@ -8,6 +11,7 @@ // CPU registers that has to be preserved (see [RG64]): .A // + SCREEN: // There are only 2 sane ways to implement this routine, diff --git a/c64/kernal/screen/screen_add_40_to_pntr.s b/c64/kernal/screen/screen_add_40_to_pntr.s deleted file mode 100644 index ff5d9f36..00000000 --- a/c64/kernal/screen/screen_add_40_to_pntr.s +++ /dev/null @@ -1,10 +0,0 @@ - - -screen_add_40_to_PNTR: - - lda PNTR - clc - adc #40 - sta PNTR - - rts diff --git a/c64/kernal/screen/screen_advance_to_next_line.s b/c64/kernal/screen/screen_advance_to_next_line.s new file mode 100644 index 00000000..c711e292 --- /dev/null +++ b/c64/kernal/screen/screen_advance_to_next_line.s @@ -0,0 +1,22 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + +screen_advance_to_next_line: + + // Check if we are at the bottom of the screen + ldy TBLX + cpy #24 + bne !+ + + // We need to scroll the screen up + jsr screen_scroll_up +!: + inc TBLX + + // Set PNTR to 0 (for continued line will be fixed later) + lda #$00 + sta PNTR + + jmp chrout_screen_calc_lptr_done diff --git a/c64/kernal/screen/screen_calculate_line_pointer.s b/c64/kernal/screen/screen_calculate_line_pointer.s deleted file mode 100644 index d982a38d..00000000 --- a/c64/kernal/screen/screen_calculate_line_pointer.s +++ /dev/null @@ -1,54 +0,0 @@ - -screen_calculate_line_pointer: - jsr screen_normalize_xy - - // Reset pointer to start of screen - lda HIBASE - sta PNT+1 - lda #0 - sta PNT+0 - - // Add 40 for every line, or 80 if the lines are linked - ldx TBLX - -!: - // Stop if we have counted enough lines - beq !+ - - // Add 40 or 80 based on whether the line is linked - // or not. - ldy #40 - // -1 offset is because we count down from N to 1, not - // N-1 to 0. - lda LDTBL-1,x - bpl sclp_l1 - ldy #80 -sclp_l1: - // Add computed line length to pointer value - tya - clc - adc PNT+0 - sta PNT+0 - lda PNT+1 - adc #0 - sta PNT+1 - - // Loop back to next line - dex - jmp !- -!: - - // FALLTHROUGH - -update_colour_line_pointer: - // Now setup pointer to colour RAM - lda PNT+0 - sta USER+0 - lda PNT+1 - sec - sbc HIBASE - clc - adc #>$d800 - sta USER+1 - - rts diff --git a/c64/kernal/screen/screen_calculate_pnt_user.s b/c64/kernal/screen/screen_calculate_pnt_user.s new file mode 100644 index 00000000..ce477aa3 --- /dev/null +++ b/c64/kernal/screen/screen_calculate_pnt_user.s @@ -0,0 +1,55 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Set pointers PNT and USER to current screen line +// + + +screen_calculate_PNT_USER: + + ldx TBLX + + // FALLTROUGH + +screen_calculate_PNT_USER_from_X: // entry point for screen_clear_line + + // Reset pointer to start of screen + + lda HIBASE + sta PNT+1 + lda #$00 + sta PNT+0 + + // Add 40 to PNT for every line + + cpx #$00 + beq screen_calculate_USER +!: + lda #40 + clc + adc PNT+0 + sta PNT+0 + bcc !+ + inc PNT+1 +!: + dex + bne !-- + + // FALLTROUGH + +screen_calculate_USER: + + // Calculate USER (pointer to the current line in color RAM) + + lda PNT+0 + sta USER+0 + lda PNT+1 + sec + sbc HIBASE + clc + adc #>$d800 + sta USER+1 + + rts diff --git a/c64/kernal/screen/screen_calculate_pntr_lnmx.s b/c64/kernal/screen/screen_calculate_pntr_lnmx.s new file mode 100644 index 00000000..7b4e7f5f --- /dev/null +++ b/c64/kernal/screen/screen_calculate_pntr_lnmx.s @@ -0,0 +1,63 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Sets PNTR in a proper range (0-39 or 40-79) +// Sets LNMX to 39 or 79 +// + + +screen_calculate_PNTR_LNMX: + + ldy TBLX + lda LDTBL, y + php + jsr screen_get_clipped_PNTR + plp + bmi screen_calculate_PNTR_0_39 + + // FALLTROUGH + +screen_calculate_PNTR_40_79: + + tya + clc + adc #40 + tay + + // FALLTROUGH + +screen_calculate_PNTR_0_39: + + sty PNTR + + // FALLTROUGH + +screen_calculate_LNMX: + + ldy TBLX + lda LDTBL, y + bpl screen_calculate_lnmx_79 // this line is a continuation + + cpy #24 + beq screen_calculate_lnmx_39 // this is the last line, which is not a continuation + + iny + lda LDTBL, y + bpl screen_calculate_lnmx_79 // line is continued + + // FALLTROUGH + +screen_calculate_lnmx_39: + + lda #39 + skip_2_bytes_trash_nvz + + // FALLTROUGH + +screen_calculate_lnmx_79: + + lda #79 + sta LNMX + rts diff --git a/c64/kernal/screen/screen_check_space_ends_line.s b/c64/kernal/screen/screen_check_space_ends_line.s new file mode 100644 index 00000000..a482dc9e --- /dev/null +++ b/c64/kernal/screen/screen_check_space_ends_line.s @@ -0,0 +1,13 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + +screen_check_space_ends_line: + + jsr screen_get_logical_line_end_ptr + + lda (PNT), y + cmp #$20 + + rts diff --git a/c64/kernal/screen/screen_code_to_petscii.s b/c64/kernal/screen/screen_code_to_petscii.s index 3485a3b9..7a76aae3 100644 --- a/c64/kernal/screen/screen_code_to_petscii.s +++ b/c64/kernal/screen/screen_code_to_petscii.s @@ -1,3 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + screen_code_to_petscii: cmp #$1B diff --git a/c64/kernal/screen/screen_get_cliped_pntr.s b/c64/kernal/screen/screen_get_cliped_pntr.s new file mode 100644 index 00000000..761ffd92 --- /dev/null +++ b/c64/kernal/screen/screen_get_cliped_pntr.s @@ -0,0 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Get PNTR value clipped to 0-39 range in .Y, sets flags to compare with 0, can trash .A +// + +screen_get_clipped_PNTR: + + ldy PNTR + cpy #40 + bcc !+ + tya + sbc #40 + tay +!: + cpy #$00 + rts diff --git a/c64/kernal/screen/screen_get_current_line_logical_length.s b/c64/kernal/screen/screen_get_current_line_logical_length.s deleted file mode 100644 index 9d8aafc1..00000000 --- a/c64/kernal/screen/screen_get_current_line_logical_length.s +++ /dev/null @@ -1,11 +0,0 @@ - -screen_get_current_line_logical_length: - ldy TBLX - lda LDTBL,y - bpl !+ - lda #79 - .byte $2c // BIT absolute mode, which we use to skip the next two instruction bytes -!: - lda #39 - sta LNMX - rts \ No newline at end of file diff --git a/c64/kernal/screen/screen_get_logical_line_end_ptr.s b/c64/kernal/screen/screen_get_logical_line_end_ptr.s new file mode 100644 index 00000000..e54bdd3d --- /dev/null +++ b/c64/kernal/screen/screen_get_logical_line_end_ptr.s @@ -0,0 +1,28 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + +screen_get_logical_line_end_ptr: + + ldy TBLX + cpy #24 + bcs screen_get_logical_line_end_39 // last line of the screen + + lda LDTBL+0, y + bpl screen_get_logical_line_end_39 // current line continues previous one + + lda LDTBL+1, y + bmi screen_get_logical_line_end_39 // current line is not continued + + // FALLTROUGH + +screen_get_logical_line_end_79: + + ldy #79 + rts + +screen_get_logical_line_end_39: + + ldy #39 + rts diff --git a/c64/kernal/screen/screen_grow_logical_line.s b/c64/kernal/screen/screen_grow_logical_line.s index a4ac0b48..92654151 100644 --- a/c64/kernal/screen/screen_grow_logical_line.s +++ b/c64/kernal/screen/screen_grow_logical_line.s @@ -1,157 +1,143 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE +screen_grow_logical_line_done_scroll: + + inc TBLX + + // FALLTROUGH + screen_grow_logical_line_done: - rts + + jmp screen_calculate_PNT_USER + + +screen_grow_logical_line_screen_up: + + jsr screen_scroll_up + + // FALLTROUGH + screen_grow_logical_line: + + // Do not grow line if previus one is grown + ldy TBLX + lda LDTBL+0, y + bpl screen_grow_logical_line_done_scroll + + // If last line, scroll the screen up + cpy #24 + beq screen_grow_logical_line_screen_up + + // Do not grow line if already grown + lda LDTBL+1, y + bpl screen_grow_logical_line_done - // Do not grow line if it is already grown - ldy TBLX - lda LDTBL,y - bmi screen_grow_logical_line_done + // Preserve SAL and EAL + + jsr screen_preserve_sal_eal + + // Scroll LDTBL down (start from the end) + ldy #23 +!: + cpy TBLX + beq !+ + bcc !+ + + lda LDTBL+0, y + sta LDTBL+1, y - // Do not grow line if previous grown dey - bmi !+ - lda LDTBL,y - bmi screen_grow_logical_line_done + bne !- !: - iny - // Mark current line as grown - lda #$80 - sta LDTBL,y - - // Now make space for the extra line added. - // If we are on the last physical line of the screen, - // Then we need to scroll the screen up - jsr screen_scroll_up_if_on_last_line - - // Count the number of physical lines to scroll down - ldx #$01 ldy TBLX -!: - iny - cpy #23 - bcs !+ + lda #$00 + sta LDTBL+1, y - lda LDTBL,y - bmi !- - inx - bne !- // branch always -!: - cpx #$00 - beq no_copy_down + // Now we have to scroll lines downwards to make space. We start from the end, + // and work backwards. We cannot be as simple and efficient here as we are + // for scrolling up, because we do not know how much must be scrolled. - // Scroll screen down to make space - // As we are scrolling down, we start from the end, - // and work backwards. We can't be as simple and efficient - // here as we are for scrolling up, because we don't know - // how much must be scrolled. - // Simple solution is to work out how many physical lines - // need shifting down, and then move lines at a time after - // initialising the pointers to the end area of the screen. + // Work out how many physical lines to scroll down - // Preserve EAL - lda EAL+0 - pha - lda EAL+1 - pha + lda #23 + sec + sbc TBLX + beq screen_grow_logical_line_copy_done // branch if no need to copyy + tax - // XXX fix TBLX value, it seems to show logical line number, which is wrong! + // Prepare initial SAL/EAL/PNT/USER values - // Set pointers to end of screen line, and one line - // above. (It is always one physical line, because - // this can only happen when expanding a line from 40 to - // 80 characters). - // XXX - This is not very efficient, and longer than it - // needs to be. Better would be to work out size to - // copy, and count it down in a pointer somewhere, so - // that loop iteration logic is simpler. lda HIBASE clc adc #3 - sta PNT+1 sta SAL+1 - lda #>$DBC0 sta EAL+1 + + lda #>$DB00 // 3rd page of the color memory + sta PNT+1 sta USER+1 - lda #<$03C0 - sta PNT+0 + lda #<$03C0 // start of destination row + sta EAL+0 sta USER+0 - // souce address is line above + lda #<$0398 // start of source row + sta SAL+0 + sta PNT+0 + +screen_grow_logical_line_loop: + + // Scroll down one line each loop iteration + + ldy #39 +!: + lda (SAL), y + sta (EAL), y + lda (PNT), y + sta (USER), y + dey + bpl !- + + // Decrement SAL/PNT pointers by 40 (optimized due to fact they share LSB) + + lda SAL+0 sec sbc #40 sta SAL+0 - sta EAL+0 + sta PNT+0 + bcs !+ + dec SAL+1 + dec PNT+1 +!: + // Decrement EAL/USER pointers by 40 (optimized due to fact they share LSB) -copy_line_down_loop: - ldy #39 -cl_inner: - lda (EAL),y - sta (USER),y - lda (SAL),y - sta (PNT),y - dey - bpl cl_inner - - // This ugly hack prevents cursor blink interference XXX solve this in better way - php - sei - jsr cursor_hide_if_visible - plp - - // Decrement all pointers by 40 - // Low bytes are in common pairs - - // Old source is new destination - // Use different registers to minimise byte similarity with C64 KERNAl - ldy SAL+1 - sty PNT+1 - lda EAL+1 - ldy SAL+0 - sta USER+1 - sty PNT+0 - sty USER+0 - - // Decrementing source pointers - lda SAL+0 + lda EAL+0 sec - sbc #<40 - sta SAL+0 + sbc #40 sta EAL+0 - lda SAL+1 - sbc #>40 - sta SAL+1 - // convert to screen equivalent - sec - sbc HIBASE - clc - adc #>$D800 - sta EAL+1 + sta USER+0 + bcs !+ + dec EAL+1 + dec USER+1 +!: + // Next loop iteration dex - bne copy_line_down_loop + bne screen_grow_logical_line_loop - // Restore EAL - pla - sta EAL+1 - pla - sta EAL+0 +screen_grow_logical_line_copy_done: -no_copy_down: - jsr screen_calculate_line_pointer + // Restore SAL and EAL - // Erase newly inserted line - ldy #79 -!: - lda COLOR - sta (USER),y - lda #$20 - sta (PNT),y - dey - cpy #39 - bne !- + jsr screen_restore_sal_eal - rts + // Erase newly inserted line and quit + + ldx TBLX + inx + jsr screen_clear_line + jmp screen_calculate_PNTR_LNMX diff --git a/c64/kernal/screen/screen_normalize_xy.s b/c64/kernal/screen/screen_normalize_xy.s deleted file mode 100644 index b4dc6ecd..00000000 --- a/c64/kernal/screen/screen_normalize_xy.s +++ /dev/null @@ -1,75 +0,0 @@ - -// -// Normalise X and Y values -// If X < 0, then make X = X + 40 (or 80, if previous line is linked) -// - -screen_normalize_xy: - - lda PNTR - bpl x_not_negative - dec TBLX - // Check that we didn't go backwards off the top of the screen - bpl !+ - lda #0 - sta TBLX - -!: jsr screen_add_40_to_PNTR - - // Check if line is linked, if so, add 40 again - ldy TBLX - lda LDTBL,y - bpl !+ - jsr screen_add_40_to_PNTR -!: - -x_not_negative: - // Work out if X is too big - ldy TBLX - lda LDTBL,y - bpl !+ - lda #79 - skip_2_bytes_trash_nvz -!: lda #39 - cmp PNTR - bcs x_not_too_big - - // X value is too big, so subtract 40 and increment Y - lda PNTR - sec - sbc #40 - sta PNTR - inc TBLX - -x_not_too_big: - - // Make sure Y isn't negative - lda TBLX - bpl !+ - lda #0 - sta TBLX -!: - // Make sure Y isn't too large for absolute size of - // screen - cmp #24 - bcc !+ - lda #24 - sta TBLX -!: - // Make sure Y isn't too much for the screen, taking - // into account the line link table - ldy #24 // max allowable line - ldx #0 -link_count_loop: - lda LDTBL,x - bpl !+ - dey -!: inx - cpx #25 - bne link_count_loop - tya - cmp TBLX - bcs y_ok - sta TBLX -y_ok: - rts diff --git a/c64/kernal/screen/screen_off.s b/c64/kernal/screen/screen_off.s index c8f811d8..154ce86f 100644 --- a/c64/kernal/screen/screen_off.s +++ b/c64/kernal/screen/screen_off.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routine to blank screen diff --git a/c64/kernal/screen/screen_on.s b/c64/kernal/screen/screen_on.s index 4742321b..24e70a1b 100644 --- a/c64/kernal/screen/screen_on.s +++ b/c64/kernal/screen/screen_on.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Helper routine to show screen diff --git a/c64/kernal/screen/screen_preserve_sal_eal.s b/c64/kernal/screen/screen_preserve_sal_eal.s new file mode 100644 index 00000000..e4f7f55f --- /dev/null +++ b/c64/kernal/screen/screen_preserve_sal_eal.s @@ -0,0 +1,34 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + +screen_preserve_sal_eal: + + plx_trash_a + ply_trash_a + + // Note: While the following routine is obvious to any skilled + // in the art as the most obvious simple and efficient solution, + // it results in a relatively long verbatim stretch of bytes when + // compared to the C64 KERNAL. Thus we have swapped the order, + // just to reduce the potential for any argument of copyright + // infringement, even though we really do not believe that the + // routine can be copyrighted due to the lack of creativity. + + lda SAL+0 + pha + lda EAL+0 + pha + lda SAL+1 + pha + lda EAL+1 + pha + + // FALLTROUGH + +screen_common_sal_eal: + + phy_trash_a + phx_trash_a + rts diff --git a/c64/kernal/screen/screen_restore_sal_eal.s b/c64/kernal/screen/screen_restore_sal_eal.s new file mode 100644 index 00000000..fd8648c5 --- /dev/null +++ b/c64/kernal/screen/screen_restore_sal_eal.s @@ -0,0 +1,29 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + + +screen_restore_sal_eal: + + plx_trash_a + ply_trash_a + + // Note: While the following routine is obvious to any skilled + // in the art as the most obvious simple and efficient solution, + // it results in a relatively long verbatim stretch of bytes when + // compared to the C64 KERNAL. Thus we have swapped the order, + // just to reduce the potential for any argument of copyright + // infringement, even though we really do not believe that the + // routine can be copyrighted due to the lack of creativity. + + pla + sta EAL+1 + pla + sta SAL+1 + pla + sta EAL+0 + pla + sta SAL+0 + + jmp screen_common_sal_eal + \ No newline at end of file diff --git a/c64/kernal/screen/screen_scroll_up_if_on_last_line.s b/c64/kernal/screen/screen_scroll_up_if_on_last_line.s deleted file mode 100644 index 1ad713cc..00000000 --- a/c64/kernal/screen/screen_scroll_up_if_on_last_line.s +++ /dev/null @@ -1,128 +0,0 @@ - -not_last_line: - rts - -screen_scroll_up_if_on_last_line: - - // Colour RAM is always in fixed place, so is easiest - // to use to check if we are on the last line. - // The last line is at $D800 + 24*40 = $DBC0 - lda USER+1 - cmp #>$DBC0 - bne not_last_line - - lda USER+0 - cmp #<$DBC0 - beq is_last_line - - jsr screen_get_current_line_logical_length - clc - adc USER+0 - cmp #<$DBE7-1 - bcc not_last_line - -is_last_line: - - dec TBLX - - // FALLTHROUGH - -scroll_screen_up: - - // Preserve EAL - lda EAL+0 - pha - lda EAL+1 - pha - - // Now scroll the whole screen up either one or two lines - // based on whether the first screen line is linked or not. - - // Get pointers to start of screen + colour RAM - lda HIBASE - sta PNT+1 - sta SAL+1 - lda #>$D800 - sta USER+1 - sta EAL+1 - lda #$00 - sta PNT+0 - sta USER+0 - - // Get pointers to screen/colour RAM source - lda LDTBL+0 - bmi !+ - lda #40 - .byte $2C // BIT $nnnn to skip next instruction -!: - lda #80 - sta SAL+0 - sta EAL+0 - - // Copy first three pages - ldy #$00 - ldx #3 -scroll_copy_loop: - lda (EAL),y - sta (USER),y - lda (SAL),y - sta (PNT),y - - iny - bne scroll_copy_loop - - inc SAL+1 - inc PNT+1 - inc EAL+1 - inc USER+1 - dex - bne scroll_copy_loop - - // Copy last partial page - // We need to copy 1000-(3*256)-line length - // = 232 - line length - lda SAL+0 - lda #232 - sec - sbc SAL+0 - tax -scroll_copy_loop2: - lda (EAL),y - sta (USER),y - lda (SAL),y - sta (PNT),y - iny - dex - bne scroll_copy_loop2 - - // Restore EAL - pla - sta EAL+1 - pla - sta EAL+0 - - // Fill in scrolled up area - ldx SAL+0 -scroll_copy_loop3: - lda COLOR - sta (USER),y - lda #$20 - sta (PNT),y - iny - dex - bne scroll_copy_loop3 - - // Shift line linkage list - ldy #0 - ldx #24 -link_copy: - lda LDTBL+1,y - sta LDTBL+0,y - iny - dex - bne link_copy - // Clear line link flag of last line - stx LDTBL+24 - - // Restore correct line pointers - jmp screen_calculate_line_pointer diff --git a/c64/kernal/tape/load_tape_normal.s b/c64/kernal/tape/load_tape_normal.s index d35d59ce..f1ae13fa 100644 --- a/c64/kernal/tape/load_tape_normal.s +++ b/c64/kernal/tape/load_tape_normal.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (normal) part of the LOAD routine @@ -31,6 +34,7 @@ // XXX use pilot to calibrate reading speed +// XXX add error correction #if CONFIG_TAPE_NORMAL @@ -40,22 +44,28 @@ load_tape_normal: jsr tape_ditch_verify // only LOAD is supported, no VERIFY - // Setup CIA #2 timers - - ldx #$03 // set timer A to 4 ticks - stx CIA2_TIMALO // $DD04 - ldx #$00 - stx CIA2_TIMAHI // $DD05 +#if CONFIG_TAPE_AUTODETECT - stx CIA2_TIMBHI // $DD07 - dex // puts $FF - for running timer B as long as possible - stx CIA2_TIMBLO // $DD06 + // Prepare for sound effects in case of turbo takeover + jsr tape_clean_sid - // Let timer A run continuously +#endif + + // Start playing + jsr tape_common_prepare_cia + jsr tape_ask_play + +#if CONFIG_TAPE_AUTODETECT + + // FALLTROUGH + +load_tape_normal_takeover: // entry point for turbo->normal takeover + + jsr tape_common_autodetect + bcs_16 load_tape_turbo_takeover + +#endif - ldx #%00010001 // start timer, force latch reload - stx CIA2_CRA // $DD0E - // Temporarily store MEMUSS in EAL lda MEMUSS+1 @@ -63,10 +73,6 @@ load_tape_normal: lda MEMUSS+0 sta EAL+0 - // Start playing - - jsr tape_ask_play - // FALLTROUGH load_tape_normal_header: @@ -91,7 +97,7 @@ load_tape_normal_header: lda (TAPE1),y cmp #$05 - beq_far tape_load_error // end of tape mark, nothing to load + beq_16 tape_load_error // end of tape mark, nothing to load cmp #$01 beq !+ @@ -124,10 +130,10 @@ load_tape_normal_payload: jsr tape_normal_pilot_data ldy #$00 // no data size limit jsr tape_normal_get_data - bcs_far tape_load_error + bcs_16 tape_load_error jsr lvs_check_EAL - bne_far tape_load_error // amount of data read does not match header info + bne_16 tape_load_error // amount of data read does not match header info jmp tape_load_success diff --git a/c64/kernal/tape/load_tape_turbo.s b/c64/kernal/tape/load_tape_turbo.s index d70facfc..fa470180 100644 --- a/c64/kernal/tape/load_tape_turbo.s +++ b/c64/kernal/tape/load_tape_turbo.s @@ -1,15 +1,14 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) part of the LOAD routine // -// Based on routine by enthusi/Onslaught, found here: +// Initially based on routine by enthusi/Onslaught, found here: // - https://codebase64.pokefinder.org/doku.php?id=base:turbotape_loader_source - - -// XXX use calibration bits to improve reading -// XXX find out how to use B0 tape timing -// XXX put header type into (TAPE1) +// but heavily reworked since then. Still, original authors deserve credits! #if CONFIG_TAPE_TURBO @@ -19,19 +18,26 @@ load_tape_turbo: jsr tape_ditch_verify // only LOAD is supported, no VERIFY - lda #$00 - sta CIA2_TIMAHI // $DD05 - lda #$FE // timer threshold for TurboTape - sta CIA2_TIMALO // $DD04 - // Prepare for sound effects jsr tape_clean_sid // Start playing + jsr tape_common_prepare_cia jsr tape_ask_play // FALLTROUGH +#if CONFIG_TAPE_AUTODETECT + +load_tape_turbo_takeover: // entry point for turbo->normal takeover + + jsr tape_common_autodetect + bcc_16 load_tape_normal_takeover + +#endif + + // FALLTROUGH + load_tape_turbo_header: // Read file header; structure described here: @@ -45,6 +51,9 @@ load_tape_turbo_header: // 16 bytes - filename, padded with 0x20 jsr tape_turbo_sync_header +#if CONFIG_TAPE_AUTODETECT + bcs_16 load_tape_normal_takeover // failure, probably not a turbo tape file +#endif ldy #$00 sta (TAPE1), y // store header type iny @@ -75,7 +84,7 @@ load_tape_turbo_header_loop: // Handle the header jsr tape_clean_sid - jsr tape_handle_header // XXX handle non-relocatable programs - any non-0 even header type + jsr tape_handle_header bcs load_tape_turbo_header // if name does not match, look for other header // FALLTROUGH @@ -100,8 +109,11 @@ load_tape_turbo_payload: sta PRTY // Read file payload - +!: jsr tape_turbo_sync_payload +#if CONFIG_TAPE_AUTODETECT + bcs !- +#endif // FALLTROUGH @@ -131,7 +143,7 @@ load_tape_turbo_loop: // Verify the checksum cpx PRTY - beq_far tape_load_success + beq_16 tape_load_success jmp tape_load_error diff --git a/c64/kernal/tape/tape_common.s b/c64/kernal/tape/tape_common.s index a74db3af..e2461a05 100644 --- a/c64/kernal/tape/tape_common.s +++ b/c64/kernal/tape/tape_common.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Common routines for tape support @@ -26,7 +29,7 @@ tape_break_error: tape_ask_play: - sei // timing is critical for tape loading +#if !CONFIG_TAPE_NO_KEY_SENSE // First check whether the button is already pressed @@ -34,6 +37,8 @@ tape_ask_play: and #$10 beq tape_wait_play_done +#endif + // Display message ldx #__MSG_KERNAL_PRESS_PLAY @@ -41,9 +46,10 @@ tape_ask_play: // FALLTROUGH +#if !CONFIG_TAPE_NO_KEY_SENSE + tape_wait_play_loop: - jsr udtim_keyboard jsr STOP bcs tape_break_error @@ -51,6 +57,26 @@ tape_wait_play_loop: and #$10 // check for pressed button bne tape_wait_play_loop + // FALLTROUGH + +#else + + // We have no key sense - so just turn the motor on and wait for the first pulse + + jsr tape_motor_on + + lda #$10 +!: + bit CIA1_ICR // $DC0D + bne !- +!: + bit CIA1_ICR // $DC0D + beq !- + +#endif + + // FALLTROUGH + tape_wait_play_done: // Prepare for reading @@ -68,8 +94,12 @@ tape_wait_play_done: tape_handle_header: +#if !CONFIG_TAPE_NO_MOTOR_CONTROL + jsr tape_screen_on_motor_off +#endif + // Print FOUND + file name ldx #__MSG_KERNAL_FOUND @@ -83,11 +113,15 @@ tape_handle_header: cpy #$15 bne !- +#if !CONFIG_TAPE_NO_MOTOR_CONTROL + // Header, wait for user decision jsr tape_header_get_decision bcs tape_break_error +#endif + // Check if file name matches jsr tape_match_filename @@ -151,14 +185,20 @@ tape_handle_header: jsr lvs_display_loading_verifying + // FALLTROUGH + +#if !CONFIG_TAPE_NO_MOTOR_CONTROL + tape_handle_header_displayed: // Load the file jsr tape_screen_off_motor_on - + // FALLTROUGH +#endif + tape_return_ok: clc @@ -211,6 +251,8 @@ tape_match_loop: rts +#if !CONFIG_TAPE_NO_MOTOR_CONTROL + // // Get user decision whether to load the file or not // @@ -223,7 +265,7 @@ tape_header_get_decision: lda STKEY bpl tape_header_wait_stop // STOP pressed and #$10 - beq tape_header_wait_space // space pressed + beq tape_header_wait_space // SPACE pressed ldx #$80 jsr wait_x_bars // sets .X to 0 @@ -245,6 +287,8 @@ tape_header_wait_stop: sec rts +#endif + // // Report that file loading succeeded (or not) @@ -254,15 +298,11 @@ tape_load_success: jsr tape_screen_on_motor_off jsr lvs_display_done - - cli jmp lvs_return_last_address tape_load_error: jsr tape_screen_on_motor_off - - cli jmp lvs_load_verify_error diff --git a/c64/kernal/tape/tape_common_autodetect.s b/c64/kernal/tape/tape_common_autodetect.s new file mode 100644 index 00000000..86fefe92 --- /dev/null +++ b/c64/kernal/tape/tape_common_autodetect.s @@ -0,0 +1,100 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Tries to detect +// +// Carry clear - normal, Carry set - turbo +// + +// XXX implement fallback to autodetection in normal + + +#if CONFIG_TAPE_AUTODETECT + + +tape_common_autodetect: + + // Set screen color to something neutral, silence the audio + lda #$0B + sta VIC_EXTCOL + lda #$00 + sta SID_SIGVOL + + // FALLTROUGH + +tape_common_autodetect_retry: + + // It is not trivial to distinguish between normal and turbo, + // as short pulses of normal (and sync uses only shorts) + // have similar lengths as long pulses of turbo + + // Thus, the routine here reads certain amount of pulses + // looking for evidence for either normal or turbo system; + // in case of no evidence found, assume normal + + lda #$00 // plus = probably normal, minus = turbo + sta XSAV + + ldy #$60 // $60 pulses cover 12 bytes of turbo recording + jsr tape_normal_get_pulse // first pulse might be a garbage, ignore it + + // FALLTROUGH + +tape_common_autodetect_loop: + + jsr tape_normal_get_pulse // read pulse for detection attempt + + // If garbage found, retry detection + cmp #$28 + bcc tape_common_autodetect_retry // this is a VERY long pulse + cmp #$E8 + bcs tape_common_autodetect_retry // this is a VERY short pulse + + // First try to distinguish turbo short signal (reference: $CD) + // from normal signals (reference: $A5 or lower), these values + // give us threshold of ($CD + $A5) / 2 = $B9 + + cmp #$B9 + bcc !+ + dec XSAV // above $B9 (so signal is shorter), looks like turbo +!: + // Now try to distinguish turbo signals (reference: $B1 or higher) + // from normal medium/long signals (reference: $7D or below), these values + // give us threshold of ($B1 + $7D) / 2 = $97 + + cmp #$97 + bcs !+ + inc XSAV +!: + // The sync for turbo is not too long - if we have enough evidence, + // assume turbo recording already + + lda XSAV + cmp #$FD + beq tape_common_autodetect_turbo + + // Next iteration + dey + bpl tape_common_autodetect_loop + + // Last chance for turbo + + lda XSAV + bmi tape_common_autodetect_turbo + + // FALLTROUGH + +tape_common_autodetect_normal: + + clc + rts + +tape_common_autodetect_turbo: + + sec + rts + + +#endif diff --git a/c64/kernal/tape/tape_common_clean_sid.s b/c64/kernal/tape/tape_common_clean_sid.s index fa135bf4..80b4bbee 100644 --- a/c64/kernal/tape/tape_common_clean_sid.s +++ b/c64/kernal/tape/tape_common_clean_sid.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Clear the SID settings - for sound effects during LOAD diff --git a/c64/kernal/tape/tape_common_ditch_verify.s b/c64/kernal/tape/tape_common_ditch_verify.s index c0c6edb0..3fa1fcbb 100644 --- a/c64/kernal/tape/tape_common_ditch_verify.s +++ b/c64/kernal/tape/tape_common_ditch_verify.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Check if VERIFY asked - if yes, terminate loading diff --git a/c64/kernal/tape/tape_common_motor.s b/c64/kernal/tape/tape_common_motor.s index 800a25df..f88934da 100644 --- a/c64/kernal/tape/tape_common_motor.s +++ b/c64/kernal/tape/tape_common_motor.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Handle tape deck motor diff --git a/c64/kernal/tape/tape_common_prepare_cia.s b/c64/kernal/tape/tape_common_prepare_cia.s new file mode 100644 index 00000000..0fda0555 --- /dev/null +++ b/c64/kernal/tape/tape_common_prepare_cia.s @@ -0,0 +1,60 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Prepare CIA timers for tape reading +// + +// +// Checked under VICE, PAL, average of 256 pulses: XXX retry measurements for NORMAL, something is probably wrong +// +// normal - short - timer goes down to $A5 +// normal - medium - timer goes down to $7D +// normal - long - timer goes down to $52 +// +// turbo - short - timer goes down to $CD +// turbo - long - timer goes down to $B1 +// +// +// Measurement subroutine: .A should contain timer value, $C000-$C002 zeroed +// +// clc +// adc $C001 +// sta $C001 +// bcc !+ +// inc $C000 +// !: +// inc $C002 +// beq !+ +// rts +// !: +// lda $C000 +// .break // .A contains our average +// rts +// + +#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO + + +tape_common_prepare_cia: + + // Setup CIA #2 timers + + ldx #$03 // set timer A to 4 ticks + stx CIA2_TIMALO // $DD04 + ldx #$00 + stx CIA2_TIMAHI // $DD05 + + stx CIA2_TIMBHI // $DD07 + dex // puts $FF - for running timer B as long as possible + stx CIA2_TIMBLO // $DD06 + + // Let timer A run continuously + + ldx #%00010001 // start timer, force latch reload + stx CIA2_CRA // $DD0E + + rts + +#endif diff --git a/c64/kernal/tape/tape_common_screen.s b/c64/kernal/tape/tape_common_screen.s index f8fb8814..fe2742ac 100644 --- a/c64/kernal/tape/tape_common_screen.s +++ b/c64/kernal/tape/tape_common_screen.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Handle screen (visible/blanked) + tape deck motor (on/off), @@ -18,6 +21,15 @@ tape_screen_on_motor_off: jmp screen_on tape_screen_off_motor_on: + + // We do not want interrupts and CHROUT reenables them + sei + + // Clear keyboard buffer + lda #$00 + sta NDX + + // Set screen color lda VIC_EXTCOL sta COLSTORE diff --git a/c64/kernal/tape/tape_normal_get_bit.s b/c64/kernal/tape/tape_normal_get_bit.s index 54f9b969..a092daa1 100644 --- a/c64/kernal/tape/tape_normal_get_bit.s +++ b/c64/kernal/tape/tape_normal_get_bit.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (normal) helper routine - bit reading diff --git a/c64/kernal/tape/tape_normal_get_byte.s b/c64/kernal/tape/tape_normal_get_byte.s index d63c1d0d..98c98ee1 100644 --- a/c64/kernal/tape/tape_normal_get_byte.s +++ b/c64/kernal/tape/tape_normal_get_byte.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (normal) helper routine - byte reading diff --git a/c64/kernal/tape/tape_normal_get_data.s b/c64/kernal/tape/tape_normal_get_data.s index 21972deb..780c85ac 100644 --- a/c64/kernal/tape/tape_normal_get_data.s +++ b/c64/kernal/tape/tape_normal_get_data.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (normal) helper routine - data block reading @@ -21,10 +24,10 @@ tape_normal_get_data: lda #$00 sta RIPRTY - // Read the pilot and sync of the block + // Read sync of the block ldy #$89 jsr tape_normal_sync - bcs tape_normal_get_block_done // XXX make it more error resistant + bcs tape_normal_get_block_done jsr tape_normal_get_marker tape_normal_get_data_loop: @@ -36,7 +39,7 @@ tape_normal_get_data_loop: // Store byte, calculate checksum lda INBIT - ldy #$00 // XXX probably can be optimized out for 65C02 + ldy #$00 sta (MEMUSS), y eor RIPRTY sta RIPRTY @@ -57,7 +60,7 @@ tape_normal_get_data_loop: sec rts -tape_normal_get_checksum: // XXX handle second copy, with pilot starting from $09 +tape_normal_get_checksum: // XXX handle second copy, with pilot starting from $09 lda INBIT eor RIPRTY diff --git a/c64/kernal/tape/tape_normal_get_marker.s b/c64/kernal/tape/tape_normal_get_marker.s index eaa6c219..4106214c 100644 --- a/c64/kernal/tape/tape_normal_get_marker.s +++ b/c64/kernal/tape/tape_normal_get_marker.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (normal) helper routine - marker reading diff --git a/c64/kernal/tape/tape_normal_get_pulse.s b/c64/kernal/tape/tape_normal_get_pulse.s index cbddc175..ac4a1f02 100644 --- a/c64/kernal/tape/tape_normal_get_pulse.s +++ b/c64/kernal/tape/tape_normal_get_pulse.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (normal) helper routine - pulse reading @@ -16,7 +19,7 @@ tape_normal_get_pulse: // implementation is probably just shorter lda #$10 -!: +!: bit CIA1_ICR // $DC0D beq !- // busy loop to detect signal, restart timer afterwards lda CIA2_TIMBLO // $DD06 diff --git a/c64/kernal/tape/tape_normal_pilot.s b/c64/kernal/tape/tape_normal_pilot.s index a6f1e577..0ea7dff7 100644 --- a/c64/kernal/tape/tape_normal_pilot.s +++ b/c64/kernal/tape/tape_normal_pilot.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) helper routine - handling the pilot @@ -28,6 +31,9 @@ tape_normal_pilot_common: tape_normal_pilot_common_restart: + lda #$0B + sta VIC_EXTCOL + lda FSBLK sta ROPRTY diff --git a/c64/kernal/tape/tape_normal_sync.s b/c64/kernal/tape/tape_normal_sync.s index 7969f958..65310ab8 100644 --- a/c64/kernal/tape/tape_normal_sync.s +++ b/c64/kernal/tape/tape_normal_sync.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) helper routine - synchronization handling @@ -11,9 +14,14 @@ tape_normal_sync: + lda #$06 + sta VIC_EXTCOL + // Injest bytes of decreasing values - jsr tape_normal_get_marker // XXX handle result + jsr tape_normal_get_marker + bcs tape_normal_sync_fail // branch if end of data marker + jsr tape_normal_get_byte bcs tape_normal_sync_fail diff --git a/c64/kernal/tape/tape_turbo_bytestore.s b/c64/kernal/tape/tape_turbo_bytestore.s index 66c94081..aa70358c 100644 --- a/c64/kernal/tape/tape_turbo_bytestore.s +++ b/c64/kernal/tape/tape_turbo_bytestore.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) helper routine - storing byte uder I/O diff --git a/c64/kernal/tape/tape_turbo_get_bit.s b/c64/kernal/tape/tape_turbo_get_bit.s index a6cf343a..e636772a 100644 --- a/c64/kernal/tape/tape_turbo_get_bit.s +++ b/c64/kernal/tape/tape_turbo_get_bit.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) helper routine - bit reading @@ -12,26 +15,44 @@ tape_turbo_get_bit: - lda #$10 -!: - bit CIA1_ICR // $DC0D - beq !- // busy loop to detect signal - lda CIA2_ICR // $DD0D - pha - lda #%00011001 // start timer, one-shot, force latch reload - sta CIA2_CRA // $DD0E - pla +#if CONFIG_TAPE_NORMAL - pha // audio/video effects - asl - sta SID_SIGVOL - beq !+ - lda #$06 -!: - sta VIC_EXTCOL - pla + jsr tape_normal_get_pulse // reuse routine from NORMAL system - lsr +#else + + lda #$10 +!: + bit CIA1_ICR // $DC0D + beq !- // busy loop to detect signal, restart timer afterwards + lda CIA2_TIMBLO // $DD06 + ldx #%01010001 // start timer, force latch reload, count timer A underflows + stx CIA2_CRB // $DD0F + +#endif + + cmp SYNO // threshold + bcs !+ + + clc + ror + sta IRQTMP+0 // store half of the last measurement result for short pulse + + lda #$01 + sta SID_SIGVOL + lda #$06 + sta VIC_EXTCOL + sec + rts +!: + clc + ror + sta IRQTMP+1 // store half of the last measurement result for long pulse + + lda #$00 + sta SID_SIGVOL + sta VIC_EXTCOL + clc rts diff --git a/c64/kernal/tape/tape_turbo_get_byte.s b/c64/kernal/tape/tape_turbo_get_byte.s index d1ee0ded..7dfe6d66 100644 --- a/c64/kernal/tape/tape_turbo_get_byte.s +++ b/c64/kernal/tape/tape_turbo_get_byte.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) helper routine - byte reading @@ -14,14 +17,43 @@ tape_turbo_get_byte: + phx_trash_a lda #$01 sta INBIT // init the to-be-read byte with 1 (canary bit to mark loop end) !: jsr tape_turbo_get_bit rol INBIT bcc !- // is the initial 1 shifted into carry already? - lda INBIT // much nicer than ldx #8: dex: loop + plx_trash_a + + // Compensate for tape speed variations + + lda IRQTMP+0 // half of the last value for bit '0' + clc + adc IRQTMP+1 // half of the last value for bit '1' + sec + sbc SYNO // now we have a diff between current threshold and calculated one + beq tape_turbo_get_byte_done // branch if threshold correction not needed + + bpl !+ + + lda SYNO + cmp #($BF - 10) + beq tape_turbo_get_byte_done // do not decrease threshold too far no matter what + + dec SYNO + bne tape_turbo_get_byte_done // branch always +!: + lda SYNO + cmp #($BF + 10) + beq tape_turbo_get_byte_done // do not increase threshold too far no matter what + + inc SYNO + +tape_turbo_get_byte_done: + + lda INBIT rts diff --git a/c64/kernal/tape/tape_turbo_sync.s b/c64/kernal/tape/tape_turbo_sync.s index 1c1aedc6..d283c733 100644 --- a/c64/kernal/tape/tape_turbo_sync.s +++ b/c64/kernal/tape/tape_turbo_sync.s @@ -1,3 +1,6 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Tape (turbo) helper routine - synchronization handling @@ -10,24 +13,31 @@ #if CONFIG_TAPE_TURBO -tape_turbo_sync_common: - - jsr tape_turbo_get_bit - rol INBIT - lda INBIT - cmp #$02 - bne tape_turbo_sync_common - rts - tape_turbo_sync_header: - ldx #$FF + // Initial pulse threshold + lda #$BF // measured 128 bits '0' and 128 bits '1' under VICE, calculated average + sta SYNO + + // Synchronize with start of sync sequence + jsr tape_turbo_sync_first +#if CONFIG_TAPE_AUTODETECT + bcs tape_turbo_sync_done +#endif + + // Perform synchronization, double loop, total $C0 * $04 iterations + ldx #$C0 !: - ldy #$03 + ldy #$04 !: - jsr tape_turbo_sync_common + stx XSAV + jsr tape_turbo_get_byte + cmp #$02 + bne tape_turbo_sync_header // branch if failure + dey bne !- + ldx XSAV dex bne !-- @@ -35,7 +45,10 @@ tape_turbo_sync_header: tape_turbo_sync_payload: - jsr tape_turbo_sync_common + jsr tape_turbo_sync_first +#if CONFIG_TAPE_AUTODETECT + bcs tape_turbo_sync_done // this shopuld not happen +#endif !: ldx #$09 // 9, 8, ... !: @@ -50,7 +63,15 @@ tape_turbo_sync_payload: dex bne !- - rts +#if CONFIG_TAPE_AUTODETECT + clc +#endif + + // FALLTROUGH + +tape_turbo_sync_done: + + rts #endif // CONFIG_TAPE_TURBO diff --git a/c64/kernal/tape/tape_turbo_sync_first.s b/c64/kernal/tape/tape_turbo_sync_first.s new file mode 100644 index 00000000..caa4bff2 --- /dev/null +++ b/c64/kernal/tape/tape_turbo_sync_first.s @@ -0,0 +1,53 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Tape (turbo) helper routine - syynchronize to first byte with value $02 +// + +#if CONFIG_TAPE_TURBO + + +tape_turbo_sync_first: + +#if CONFIG_TAPE_AUTODETECT + + ldy #$00 +!: + jsr tape_turbo_get_bit + rol INBIT + lda INBIT + + cmp #$FF + bne !+ + iny + bpl !- + bmi tape_turbo_sync_first_fail // suspiciously many $FF bytes, probably not a turbo tape +!: + cmp #$02 + bne tape_turbo_sync_first + + clc + rts + +tape_turbo_sync_first_fail: + + sec + rts + +#else // no CONFIG_TAPE_AUTODETECT + + jsr tape_turbo_get_bit + rol INBIT + lda INBIT + + cmp #$02 + bne tape_turbo_sync_first + + rts + +#endif + + +#endif diff --git a/c64/kernal/time/rdtim.s b/c64/kernal/time/rdtim.s index 37009289..0271acb3 100644 --- a/c64/kernal/time/rdtim.s +++ b/c64/kernal/time/rdtim.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 291 -// - [CM64] Compute's Mapping the Commodore 64 - page 232 +// - [RG64] C64 Programmers Reference Guide - page 291 +// - [CM64] Computes Mapping the Commodore 64 - page 232 // // CPU registers that has to be preserved (see [RG64]): none // @@ -11,7 +14,7 @@ RDTIM: // Disable interrupts for the duration of the routine, to prevent - // jiffy clock update while reeading it's values + // jiffy clock update while reeading its values sei // Store the jiffy clock state @@ -24,4 +27,3 @@ RDTIM: // leaves IRQs enabled. cli rts - diff --git a/c64/kernal/time/settim.s b/c64/kernal/time/settim.s index 0bceeaf8..7c07eb5c 100644 --- a/c64/kernal/time/settim.s +++ b/c64/kernal/time/settim.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 299/300 -// - [CM64] Compute's Mapping the Commodore 64 - page 232 +// - [RG64] C64 Programmers Reference Guide - page 299/300 +// - [CM64] Computes Mapping the Commodore 64 - page 232 // // CPU registers that has to be preserved (see [RG64]): .A, .X, .Y // @@ -11,7 +14,7 @@ SETTIM: // Disable interrupts for the duration of the routine, to prevent - // jiffy clock update while changing it's values + // jiffy clock update while changing its values sei // Store the jiffy clock state @@ -24,4 +27,3 @@ SETTIM: // leaves IRQs enabled. cli rts - diff --git a/c64/kernal/time/udtim.s b/c64/kernal/time/udtim.s index 01bb3b91..9c75406f 100644 --- a/c64/kernal/time/udtim.s +++ b/c64/kernal/time/udtim.s @@ -1,9 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE // // Official Kernal routine, described in: // -// - [RG64] C64 Programmer's Reference Guide - page 303 -// - [CM64] Compute's Mapping the Commodore 64 - pages 27, 232 +// - [RG64] C64 Programmers Reference Guide - page 303 +// - [CM64] Computes Mapping the Commodore 64 - pages 27, 232 // // CPU registers that has to be preserved (see [RG64]): .Y // diff --git a/doc/Development.md b/doc/Development.md new file mode 100644 index 00000000..24760240 --- /dev/null +++ b/doc/Development.md @@ -0,0 +1,182 @@ + +# OpenROMs development guide + +NOTE: this document is a preliminary version, definitely incomplete! + + +## In-depth protocol description + +- [JiffyDOS](./Protocol-JiffyDOS.md) +- [DolphinDOS](./Protocol-DolphinDOS.md) + + +## Guidelines for software developers for OpenROMs compatibility + +Most important: always test your software on the original ROMs too. If your code works on the OpenROMs, but fails on the original firmware - than something is clearly wrong, and it might stop working once we make OpenROMs more compatible for one reason or another. + +### Unofficial ROM APIs + +Please, do not use any internal/unofficial OpenROMs API. They WILL change in an incompatible way, you may believe me. Using unofficial API of the original ROMs is OK if the routine is marked as supported in the [implementation status](../STATUS.md) document. + +### Compatibility with OpenROMs for Mega65 + +The Mega65 OpenROMs build aims to provide a C64-compatible memory map in range `$00000-$0FFFF`. For `$10000` and above, everything is still subject to change. + +Please note, that certain ROM routines are moved to additional Mega65 ROM area (2x8KB is not enough to implement full ROM functionality and additional features) - original locations contain just short compatibility code which remaps memory, calls the real routine, and restores default mapping (that means all blocks unmapped). This shouldn't be a problem for original C64 software, but can make a difference for Mega65-aware code; thus, please follow these simple rules: + +- do not call ROM routines with .B set to anything other than 0 (and .B set to 0x40 or above is a receipe for disaster!) +- be aware that ROM routines may restore the default memory mapping by means of MAP/EOM + +OpenROMs interrupt handlers do not touch the ROM mapping, range `0x4000-0xBFFF` can be freely mapped without disabling IRQ or NMI. The .Z register is mostly safe to use too - some routines might use it, but they will alwayys restore it's previous state. Please be aware, that for maximum compatibility our IRQ/NMI handlers DO NOT store/restore .Z register. + +### API extensions + +#### PETSCII + +OpenROMs provides support for several additional PETSCII codes (all compatible with C128 and/or C65): + +| PETSCII code | description | +| :----------: | :-------------------------------------------------- | +| `$07` | bell (C128 and C65 compatible), not implemented yet | +| `$1B` | `ESC` key (C128 and C65 compatible) | +| `$84` | `HELP` key (C128 and C65 compatible) | +| `$10` | `F9` key (C65 compatible) | +| `$15` | `F10` key (C65 compatible) | +| `$16` | `F11` key (C65 compatible) | +| `$17` | `F12` key (C65 compatible) | +| `$19` | `F13` key (C65 compatible) | +| `$1A` | `F14` key (C65 compatible) | + +There is no official PETSCII code for `TAB` - we can't utilize the ones from C128 or C65 because it conflicts with some C64 codes. + +#### Bucky keys + +`SHFLAG` (`$028D`) variable is extended to support additional bucky keys on C128 and C65 keyboards: + +| bits 7-5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | +| :------: | :---------: | :------: | :------: | :------: | :------: | +| reserved | `CAPS LOCK` | `ALT` | `CTRL` | `VENDOR` | `SHIFT` | + +Bits 3 and 4 are extension to the original variable, compatible with the C128 ROMs API. There is no official way to retrieve `NO_SCRL` status as of yet. The `40/80` key status cannot be retrieved in C64 mode at all (C128 hardware limitation). + + +## Tinkering with OpenROMs + +Make sure to read the main [README](../README.md) first - although any help with the project is always welcome, you need to be aware of the possible legal problems we want to avoid. + +### Make targets + +List of the most important make targets: + +| target | description | +| :------------------ | :----------------------------------------------------------------------------- | +| `all` | builds all ROMs, places them in 'build' subdirectory | +| `clean` | removes all the compilation results and intermediate files | +| `updatebin` | upates ROMs in 'bin' subdirectory - with embedded version string, for release | +| `testsimilarity` | launches the similarity tool, see [README](../README.md) | +| `test` | builds the 'custom' configuration, launches it using VICE emulator | +| `test_generic` | builds the default ROMs, for generic C64/C128, launches using VICE | +| `test_generic_x128` | as above, but launches C128 emulator instead | +| `test_mega65` | builds the Mega65 ROM, launches it using XEMU emulator | +| `test_ultimate64` | builds the Ultimate 64 configuration, launches it using VICE emulator | +| `test_hybrid` | builds a hybrid ROM (OpenROMs Kernal + original BASIC), launches it using VICE | +| `test_testing` | builds a rather odd testing configuration, launches it using VICE emulator | + + +### Code segments and ROM layouts + +Currently there are 2 ROM layouts defined: + +- `STD` - with 2 code segments: `BASIC` (`$A000-$E4D2`, where `$C000-$DFFF` is a skip-gap for RAM and I/O area) and `KERNAL` (`$E4D3 - $FFFF`) +- `M65` - where `BASIC` becames `BASIC_0` and `KERNAL` becames `KERNAL_0`, additional segments might be added to the build system in the future; at the moment of writing this document additional 8KB of ROM is defined as `KERNAL_1` segment + +To check for current ROM layout or code segment use KickAssembler preprocessor defines, like `ROM_LAYOUT_STD`, `ROM_LAYOUT_M65`, `SEGMENT_BASIC`, `SEGMENT_KERNAL_1`. + +### Fixed location vs floating routines + +There are two types of routines (in this chapter routine = single source file): + +- fixed location - they are always placed in the location specified by developer; if it's not possible, an error is produced during the compilation +- floating - their location in the ROM segment is determined during the compilation by our build segment tool; from the developer point of view it is random + +File name of the fixed location routine adheres to the scheme: `addr.name.s`, where `addr` is a 4-digit hexadecimal number. They should be accompanied with `*.interop` file, describing why the location got fixed - see [README](../README.md) for more information. + + +### Handling different ROM layouts + +For handling different ROM layouts, our build tool provides support for pragma-like comments, in the form: + +``` +// #LAYOUT# +``` + +where: + +- separators are mandatory - at least one space or tabulation has to be placed +- `` - currently `STD` or `M65`, asterisk symbol can be used to match any layout +- `` - `KERNAL`, `BASIC`, `KERNAL_0`, `KERNAL_1`, etc., asterisk symbol can be used to match any segment +- `` - what to do when layout and segment match: + +| action | description | +| :------------ | :-------------------------------------------- | +| `#IGNORE` | ignore the file completely | +| `#TAKE` | compile the file normally | +| `#TAKE-FLOAT` | compile the file, but force it to be floating | + +The first match counts, all the remaining ones are dropped. Examples: + +``` +// #LAYOUT# STD * #TAKE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE +``` + +This is a very common one. For standard ROM layout just take the file. For non-standard ones take it only for compiling `KERNAL_0` segment, ignore it for anything other (like `KERNAL_1`). Another example: + +``` +// #LAYOUT# M65 KERNAL_0 #TAKE-FLOAT +// #LAYOUT# M65 KERNAL_1 #TAKE +// #LAYOUT# * * #IGNORE +``` + +This can be found in a private (internal) jumptable of `KERNAL_1` segmment of `M65` layout. For standard ROM part (`KERNAL_0` segment) take it as floating routine (for `KERNAL_0` segment the file provides only labels for the jumptable). For `KERNAL_1` segment of `M65` layout, take it as a fixed location-routine; in such case the file will provide a jumptable itself. For memory layout other than `M65`, just ignore the file. Yet another example: + +``` +// #LAYOUT# M65 KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE +``` + +This is used for memory mapping helper routines, which are only needed for Mega65 build. They will be placed in `KERNAL_0` segment in such case. And the last example: + +``` +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 KERNAL_0 #TAKE +// #LAYOUT# M65 KERNAL_1 #TAKE-FLOAT +// #LAYOUT# * * #IGNORE +``` + +This is for the routine, that on Mega65 goes to `KERNAL_1` segment, but can still be transparently called using fixed location in `KERNAL_0` segement. The code might, for example, look this way: + +``` +ROUTINE_NAME: + +#if (ROM_LAYOUT_M65 && SEGMENT_KERNAL_0) + + jsr map_KERNAL_1 + jsr KERNAL_1__ROUTINE_NAME // execute routine from KERNAL_1 segment + jmp map_NORMAL + +#else + + // real routine, ended with RTS + +#endif +``` + +### CPU-specific optimizations + +TODO + +### Labels and VICE debugging + +Make targets which launch the VICE emulator pass al the label to the built-in monitor. Problem can arise if we have multiple labels pointing the same address - in such case VICE monitor displays a warning, and just one of the labels is being recognized. To avoid this problem please select a single main label for the given memory location, and make sure all the others contain `__` - such labels will be filtered out from the symbol file for VICE. diff --git a/src/build_segment.cc b/src/build_segment.cc index d1dc4e59..643da112 100644 --- a/src/build_segment.cc +++ b/src/build_segment.cc @@ -36,6 +36,7 @@ std::string CMD_outFile = "OUT.BIN"; std::string CMD_outDir = "./out"; std::string CMD_segName = "MAIN"; std::string CMD_segInfo = "(unnamed)"; +std::string CMD_romLayout = "STD"; int CMD_loAddress = 0xC000; int CMD_hiAddress = 0xCFFF; @@ -51,6 +52,7 @@ void printUsage() "usage: build_segment [-a ] [-o ] [-d ]" << "\n" << " [-l ] [-h ]" << "\n" << " [-s ] [-i ]" << "\n" << + " [-r ]" << "\n" << " " << "\n\n"; } @@ -77,9 +79,14 @@ class SourceFile public: SourceFile(const std::string &fileName, const std::string &dirName); + void preprocess(); + bool preprocessLine(const std::string &line); + bool nameMatch(const std::string &token, const std::string &name); + std::string fileName; std::string dirName; + bool ignore; bool floating; std::vector content; @@ -118,7 +125,7 @@ public: class Solver { public: - Solver(BinningProblem &problem) : problem(problem), logOutput(logFile, std::cout) {} + explicit Solver(BinningProblem &problem) : problem(problem), logOutput(logFile, std::cout) {} void run(); @@ -153,7 +160,7 @@ void parseCommandLine(int argc, char **argv) // Retrieve command line options - while ((opt = getopt(argc, argv, "a:o:d:s:i:l:h:")) != -1) + while ((opt = getopt(argc, argv, "a:o:d:s:i:r:l:h:")) != -1) { switch(opt) { @@ -162,6 +169,7 @@ void parseCommandLine(int argc, char **argv) case 'd': CMD_outDir = optarg; break; case 's': CMD_segName = optarg; break; case 'i': CMD_segInfo = optarg; break; + case 'r': CMD_romLayout = optarg; break; case 'l': CMD_loAddress = strtol(optarg, nullptr ,16); break; case 'h': CMD_hiAddress = strtol(optarg, nullptr ,16); break; default: printUsage(); ERROR(); @@ -193,7 +201,7 @@ void readSourceFiles() // This is a regular file char *tmp1 = strdup(objName.c_str()); - char *tmp2 = strdup(objName.c_str()); + char *tmp2 = strdup(objName.c_str()); std::string dirName = dirname(tmp1); std::string fileName = basename(tmp2); @@ -232,6 +240,11 @@ void readSourceFiles() closedir(dirHandle); } + // Filter-out files marked as ignored + + GLOBAL_sourceFiles.erase(std::remove_if(GLOBAL_sourceFiles.begin(), GLOBAL_sourceFiles.end(), + [](const SourceFile &sourceFile) -> bool { return sourceFile.ignore; }), GLOBAL_sourceFiles.end()); + if (GLOBAL_sourceFiles.empty()) ERROR("no source files found"); // Sort the file list by name, to provide deterministic results @@ -278,6 +291,7 @@ void calcRoutineSizes() outFile << "\n" << ".segment " << CMD_segName << " [start=$100, min=$100, max=$FFFF]" << "\n"; outFile << "#define SEGMENT_" << CMD_segName << "\n"; + outFile << "#define ROM_LAYOUT_" << CMD_romLayout << "\n"; for (const auto &sourceFile : GLOBAL_sourceFiles) { @@ -481,6 +495,7 @@ void compileSegment() ", outBin=\"" << CMD_outFile << "\", fill]" << "\n"; outFile << "#define SEGMENT_" << CMD_segName << "\n"; + outFile << "#define ROM_LAYOUT_" << CMD_romLayout << "\n"; outFile << ".namespace " << CMD_segName << " {" << "\n\n"; // Write files which only contain definitions (no routines) @@ -552,6 +567,7 @@ int main(int argc, char **argv) SourceFile::SourceFile(const std::string &fileName, const std::string &dirName) : fileName(fileName), dirName(dirName), + ignore(false), floating(false), startAddr(-1), codeLength(-1), @@ -602,6 +618,10 @@ SourceFile::SourceFile(const std::string &fileName, const std::string &dirName) startAddr = strtol(fileName.substr(0, 4).c_str(), nullptr ,16); } + // Preprocess the file (apply settings from the content) + + preprocess(); + // Generate KickAss compatible label from the file name label = fileName.substr(0, fileName.length() - 2); @@ -610,6 +630,83 @@ SourceFile::SourceFile(const std::string &fileName, const std::string &dirName) std::replace(label.begin(), label.end(), ',', '_'); } +void SourceFile::preprocess() +{ + std::string contentStr(content.begin(), content.end()); + std::istringstream stream(contentStr); + std::string line; + + while (std::getline(stream, line)) + { + if (line.empty()) continue; + std::replace(line.begin(), line.end(), '\t', ' '); + line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); + if (!preprocessLine(line)) break; + } +} + +bool SourceFile::preprocessLine(const std::string &line) +{ + // Split the line into tokens + + std::list tokens; + + std::istringstream stream(line); + std::string token; + while(std::getline(stream, token, ' ')) + { + if (token.empty()) continue; + tokens.push_back(token); + } + if (tokens.empty()) return true; + + // Now preprocess line using the token list + + auto iter = tokens.begin(); + + // Injest the comment token + + if ((iter++)->compare("//") != 0 || iter == tokens.end()) return true; + + // Check if supported directive + + if ((iter++)->compare("#LAYOUT#") != 0) return true; + + // Check if segment name and rom layout match + + if (iter == tokens.end()) ERROR("syntax error, missing rom layout in '#LAYOUT#'"); + if (!nameMatch(*(iter++), CMD_romLayout)) return true; + + if (iter == tokens.end()) ERROR("syntax error, missing segment name in '#LAYOUT#'"); + if (!nameMatch(*(iter++), CMD_segName)) return true; + + // Retrieve and apply action + + if (iter == tokens.end()) ERROR("syntax error, missing action in '#LAYOUT#'"); + + if (iter->compare("#IGNORE") == 0) + { + ignore = true; + } + else if (iter->compare("#TAKE-FLOAT") == 0) + { + floating = true; + } + else if (iter->compare("#TAKE") != 0) + { + ERROR(std::string("syntax error, unsupported action '") + token + "' in '#LAYOUT#'"); + } + + // Tell the caller to finish processing the file + + return false; +} + +bool SourceFile::nameMatch(const std::string &token, const std::string &name) +{ + return (token.compare("*") == 0) || (token.compare(name) == 0); +} + // // Class 'BinningProblem' // @@ -625,7 +722,7 @@ BinningProblem::BinningProblem(int loAddress, int hiAddress) gaps[loAddress] = hiAddress - loAddress + 1; - // Initial value of statistics + // Initial value of statistics statSize = gaps[loAddress]; statFree = gaps[loAddress]; @@ -667,7 +764,7 @@ void BinningProblem::addToProblem(SourceFile *routine) // Put the routine into the gap, possibly removing it or splitting into two fixedRoutines[routine->startAddr] = routine; - statFree -= routine->codeLength; + statFree -= routine->codeLength; // Calculate possible new gap after the routine @@ -694,7 +791,8 @@ void BinningProblem::addToProblem(SourceFile *routine) if (!gapFound) { - ERROR(std::string("start address of fixed address file '") + routine->fileName + "' already occupied"); + ERROR(std::string("start address of fixed address file '") + \ + routine->fileName + "' already occupied or out of range"); } } } diff --git a/strings/0320EAE8 b/strings/0320EAE8 new file mode 100644 index 00000000..d1ad6f06 --- /dev/null +++ b/strings/0320EAE8 @@ -0,0 +1,3 @@ +$03 + JSR $E8EA + +Instruction (calling a well-known subroutine for screen line scrolling) + some part. Trivial, not copyrightable. diff --git a/strings/034C13 b/strings/034C13 new file mode 100644 index 00000000..f96f8a1d --- /dev/null +++ b/strings/034C13 @@ -0,0 +1,3 @@ +$03 + JMP$xx13 + +Not even a full instruction. Trivial - not coprightable. diff --git a/strings/03A90085 b/strings/03A90085 new file mode 100644 index 00000000..d5af9d35 --- /dev/null +++ b/strings/03A90085 @@ -0,0 +1,3 @@ +$03 + LDA #$00 + STA (zeropage address does not match) + +Instruction (loading 0 to accumulator) + some parts. Trivial - not copyrightable. diff --git a/strings/1820FFE9 b/strings/1820FFE9 new file mode 100644 index 00000000..75f7360d --- /dev/null +++ b/strings/1820FFE9 @@ -0,0 +1,3 @@ +$18 + JSR $E9FF + +Call to a well-known routine + some part. Trivial - not copyrightable. diff --git a/strings/2902D007 b/strings/2902D007 new file mode 100644 index 00000000..b0755a85 --- /dev/null +++ b/strings/2902D007 @@ -0,0 +1,3 @@ +AND #$02 + BNE (offset matches) + +Check for some bits in the accumulator. Trivial - not copyrightable. diff --git a/strings/48A5AD48A5 b/strings/48A5AD48A5 new file mode 100644 index 00000000..00ab3df4 --- /dev/null +++ b/strings/48A5AD48A5 @@ -0,0 +1,3 @@ +PHA + LDA $AD + PHA + LDA (zeropage address does not match) + +Part of the instruction sequence restoring a well-known 16-bit zeropage variable from a stack. Trivial - not copyrightable. diff --git a/strings/48A5AE48 b/strings/48A5AE48 new file mode 100644 index 00000000..6eba012c --- /dev/null +++ b/strings/48A5AE48 @@ -0,0 +1,3 @@ +PHA + LDA $AE + PHA + +Retrievin some data from the stack, among them matching zeropage variable. Trivial - not copyyrightable. diff --git a/strings/48A5AE48A5 b/strings/48A5AE48A5 new file mode 100644 index 00000000..67b669f3 --- /dev/null +++ b/strings/48A5AE48A5 @@ -0,0 +1,3 @@ +PHA + LDA $AE + PHA + LDA (zeropage address does not match) + +Part of the instruction sequence restoring a well-known 16-bit zeropage variable from a stack. Trivial - not copyrightable. diff --git a/strings/6885AD6885 b/strings/6885AD6885 new file mode 100644 index 00000000..5425bbeb --- /dev/null +++ b/strings/6885AD6885 @@ -0,0 +1,3 @@ +PHA + STA $AD + PHA + STA (zeropage address does not match) + +Part of the instruction sequence storing a well-known 16-bit zeropage variable on a stack. Trivial - not copyrightable. diff --git a/strings/6885AE6885 b/strings/6885AE6885 new file mode 100644 index 00000000..c42430a0 --- /dev/null +++ b/strings/6885AE6885 @@ -0,0 +1,3 @@ +PHA + STA $AE + PHA + STA (zeropage address does not match) + +Part of the instruction sequence storing a well-known 16-bit zeropage variable on a stack. Trivial - not copyrightable. diff --git a/strings/78A90085 b/strings/78A90085 new file mode 100644 index 00000000..2b7174c0 --- /dev/null +++ b/strings/78A90085 @@ -0,0 +1,3 @@ +SEI + LDA #$00 + STA (zeropage address does not match) + +Disable interrupts, store 0 in some memoryy location (address does not match). Trivial and not creative - not copyrightable. diff --git a/strings/84D34C b/strings/84D34C new file mode 100644 index 00000000..de73cd5c --- /dev/null +++ b/strings/84D34C @@ -0,0 +1,3 @@ +STY $D3 + JMP (address does not match) + +Instruction (storing data in a well-known memory location) + some part. Trivial - not copyrightable. diff --git a/strings/86D6206CE5A4 b/strings/86D6206CE5A4 new file mode 100644 index 00000000..08a745bd --- /dev/null +++ b/strings/86D6206CE5A4 @@ -0,0 +1,3 @@ +STX $D6 + JSR $E56C + LDY (zeropage address deos not match) + +Update one screen-related value with coontent of X register, call a well-known routine to adjust remaining ones - trivial, not copyrightable. diff --git a/strings/880285AD b/strings/880285AD new file mode 100644 index 00000000..b8940f30 --- /dev/null +++ b/strings/880285AD @@ -0,0 +1,3 @@ +$0288 + STA $AD + +Instruction + some part (address of a documented variable). Trivial - not copyrioghtable. diff --git a/strings/8A48A901 b/strings/8A48A901 new file mode 100644 index 00000000..efecae4e --- /dev/null +++ b/strings/8A48A901 @@ -0,0 +1,3 @@ +TXA + PHA + LDA #$01 + +Store .X register on the stack (would be a single instruction on 65C02) + loading accumulator with 1. Trivial and not creative - not copyrightable. diff --git a/strings/98488A48 b/strings/98488A48 new file mode 100644 index 00000000..9455ce34 --- /dev/null +++ b/strings/98488A48 @@ -0,0 +1,3 @@ +TYA + PHA + TXA + PHA + +Store Y and X CPU registers on a stack (would be only 2 instruction on 65C02 and above). Trivial - not copyrightable. diff --git a/strings/A00098912B b/strings/A00098912B new file mode 100644 index 00000000..f09592a6 --- /dev/null +++ b/strings/A00098912B @@ -0,0 +1,3 @@ +LDY #$00 + TYA + STA ($2B),Y + +6502 way to store 0 in a memory location pointed by a well-known pointer. Trivial - not copyrightable. diff --git a/strings/A002A9008D b/strings/A002A9008D new file mode 100644 index 00000000..bb7f0991 --- /dev/null +++ b/strings/A002A9008D @@ -0,0 +1,3 @@ +LDY #$02 + LDA #$00 + STA (address does not match) + +Put $02 to Y register, put 0 into accumulator and store it somewhere (address does not match) - trivial, not copyrightable. diff --git a/strings/A027B1AC91 b/strings/A027B1AC91 new file mode 100644 index 00000000..a92ffd34 --- /dev/null +++ b/strings/A027B1AC91 @@ -0,0 +1,3 @@ +LDY #$27 + LDA ($AC),Y + STA (zeroopage address deos not match),Y + +Get the last character from the screen line (using a documented vector) and store it somewhere (details differ here). Trivial - not copyrightable. diff --git a/strings/A0E4201EAB b/strings/A0E4201EAB new file mode 100644 index 00000000..0f2811e8 --- /dev/null +++ b/strings/A0E4201EAB @@ -0,0 +1,3 @@ +LDY #$E4 + JSR $AB1E + +Print a string by calling a well-known routine, only part of the string address matches. Trivial - not copyrightable. diff --git a/strings/A21820FFE9 b/strings/A21820FFE9 new file mode 100644 index 00000000..93505a11 --- /dev/null +++ b/strings/A21820FFE9 @@ -0,0 +1,3 @@ +LDX #$18 + JSR $E9FF + +Clear the last screen line by calling a well-known routine. Trivial - not copyrightable. diff --git a/strings/A21820FFE9CA10FA b/strings/A21820FFE9CA10FA new file mode 100644 index 00000000..a1806b8c --- /dev/null +++ b/strings/A21820FFE9CA10FA @@ -0,0 +1,3 @@ +LDX #$18 + JSR $E9FF + DEX + BPL (go back to JSR) + +Clear the whole screen by repeatedly calling a well-known routine to clear a single line. Not creative - not copyrightable. diff --git a/strings/A5AC48A5 b/strings/A5AC48A5 new file mode 100644 index 00000000..63d8d863 --- /dev/null +++ b/strings/A5AC48A5 @@ -0,0 +1,3 @@ +LDA $AC + PHA + LDA (zeropage address does not match) + +Storing some data on a stack, among them the same zeropage variable - trivial, not copyrightable. diff --git a/strings/A9012CA9 b/strings/A9012CA9 new file mode 100644 index 00000000..ad7929dc --- /dev/null +++ b/strings/A9012CA9 @@ -0,0 +1,3 @@ +LDA #$01 + BIT (to skip next instruction) + LDA # (value does not match) + +Setting accumulator to $01 or some other value (not included in similarity) depending on some condition (also not included in the similarity). Trivial - not copyrightable. diff --git a/strings/A9012CA900 b/strings/A9012CA900 new file mode 100644 index 00000000..38f139a6 --- /dev/null +++ b/strings/A9012CA900 @@ -0,0 +1,3 @@ +LDA #$01 + BIT (skip next instruction) + LDA #$00 + +Part of code setting accumulator to 0 or 1 depending on some condition (check not included in similarity). Trivial - not copyrightable. diff --git a/strings/A92091D18810 b/strings/A92091D18810 new file mode 100644 index 00000000..b3c3ff46 --- /dev/null +++ b/strings/A92091D18810 @@ -0,0 +1,3 @@ +LDA #$20 + STA ($D1),Y + DEY + BPL (offset does not match) + +Part of the loop filling area of the screen with spaces. Not creative - not coprightable. diff --git a/strings/AA68A8 b/strings/AA68A8 new file mode 100644 index 00000000..8e8695af --- /dev/null +++ b/strings/AA68A8 @@ -0,0 +1,3 @@ +TAX + PLA + TAY + +Simple register manipulation to retrieve .Y from the stack without losing .A. Trivial - not copyrightable. diff --git a/strings/AA68A8A5 b/strings/AA68A8A5 new file mode 100644 index 00000000..1d8d9bb0 --- /dev/null +++ b/strings/AA68A8A5 @@ -0,0 +1,3 @@ +TAX + PLA + TAY + LDA (zeropage address does not match) + +Some simple stack/register data transfer + loading accumulator from memory (address does not match) - trivial. Not copyrightable. diff --git a/strings/C385AEA5 b/strings/C385AEA5 new file mode 100644 index 00000000..a93143e2 --- /dev/null +++ b/strings/C385AEA5 @@ -0,0 +1,3 @@ +$C3 + STA $AE + LDA (zeropage adddress does not match) + +Instruction + some parts. Trivial - noot copyrightable. diff --git a/strings/C8B1D18891D1C8 b/strings/C8B1D18891D1C8 new file mode 100644 index 00000000..aa5caeac --- /dev/null +++ b/strings/C8B1D18891D1C8 @@ -0,0 +1,3 @@ +INY + LDA ($D1),Y + DEY + STA ($D1),Y + INY + +Part of the loop moving some memory content (pointed by a zeropage variable) by 1 byte. Not creative - not copyrightable. diff --git a/strings/C8B1F38891F3C8 b/strings/C8B1F38891F3C8 new file mode 100644 index 00000000..6f3b39af --- /dev/null +++ b/strings/C8B1F38891F3C8 @@ -0,0 +1,3 @@ +INY + LDA ($F3),Y + DEY + STA ($F3),Y + INY + +Part of the loop moving some memory content (pointed by a zeropage variable) by 1 byte. Not creative - not copyrightable. diff --git a/strings/D0F5A98085 b/strings/D0F5A98085 new file mode 100644 index 00000000..d5a1416c --- /dev/null +++ b/strings/D0F5A98085 @@ -0,0 +1,3 @@ +BNE (offset matches) + LDA #$80 + STA (zeropage address does not match) + +Depending on some condition (check does not fully match) store $80 in some memoryy location (address does not match). Trivial - not copyrightable. diff --git a/strings/E4201EAB b/strings/E4201EAB new file mode 100644 index 00000000..e420158b --- /dev/null +++ b/strings/E4201EAB @@ -0,0 +1,3 @@ +$E4 + JSR $AB1E + +Call to a well-known routine + some part. Trivial - not copyrightable. diff --git a/strings/EAA5012910 b/strings/EAA5012910 new file mode 100644 index 00000000..00f8009c --- /dev/null +++ b/strings/EAA5012910 @@ -0,0 +1,3 @@ +$EA + LDA $01 + AND #$10 + +Clearing bit on bte fetched from a documented hardware port + some part of other instruction. Trivial - not copyyrightable. diff --git a/strings/EC186020 b/strings/EC186020 new file mode 100644 index 00000000..5bb258f9 --- /dev/null +++ b/strings/EC186020 @@ -0,0 +1,3 @@ +$EC + CLC + RTS (end of routine) + JSR (address does not match) + +Routine ending with enabling interrupts + beginning of another one (just instruction opcode matches, not the argument). Trivial - not copyrightable. diff --git a/strings/FF2006 b/strings/FF2006 new file mode 100644 index 00000000..fd18433d --- /dev/null +++ b/strings/FF2006 @@ -0,0 +1,3 @@ +$FF + JSR$xx06 + +Not even a full instruction. Trivial - not copyrightable.