Code cleanup

This commit is contained in:
romych committed 2026-04-01 14:57:08 +03:00
1 parent 603ebac8a6
commit 06cde90dac
165 files changed
+24723 -4325

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
# Эмулятор персонального компьютера Океан-240.2
## Пример, кода для работы в среде VSCode.
1. Установите VSCode
2. Установите плагин DeZog для возможности отладки исходного кода в эмуляторе okemu
3. Откройте в VSCode папку examples/hello
4. Запустите эмулятор okemu
5. Запустите отладку через меню Run -> Start debuging в VSCode.
6. Используйте инструменты отладки VSCode для выполнения кода, просмотра регистров процессора и состояния памяти и т.д.
## Рекомендуемые плагины VSCode
- [mborik.z80-macroasm-vscode](https://github.com/mborik/z80-macroasm-vscode) - Раскраска синтаксиса ассемблера Z80, поддержка разных ассемблеров, переименование меток и т.п.
- [maziac.dezog](https://github.com/maziac/DeZog/) - Отладчик кода Z80 с помощью эмуляторов
- [maziac.hex-hover-converter](https://github.com/maziac/hex-hover-converter) - Перевод чисел в другие системы счисления при наведении курсора
- [maziac.z80-instruction-set](https://github.com/maziac/z80-instruction-set) - Подсказки по инструкциям Z80 при наведении курсора (коды, такты, влияние на флаги)
## Пример файла .vscode/tasks.json
Конфигурация задачи для компиляции исходного кода ассемблером [sjasmplus](https://github.com/z00m128/sjasmplus)
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "make (sjasmplus)", // так задача будет называться в меню Terminal -> Run task... VSCode
"type": "shell",
"command": "sjasmplus",
"args": [
"--i8080", // используем только инструкции КР580ВМ80
"--sld=main.sld", // генерируем файл с таблицей символов для отладчика
"--raw=main.obj", // сохраняем результат компиляции в двоичный файл
"--fullpath",
"main.asm" // основной файл исходного кода программы
],
"problemMatcher": "$problem-matcher-sjasmplus",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
```
## Пример файла .vscode/launch.json
Конфигурация задачи для отладки исходного кода нашей программы с помощью эмулятора okemu. Эмулятор поддерживает подмножество протокола ZRCP (протокол отладки эмулятора [ZEsarUX](https://github.com/chernandezba/zesarux)).
Для отладки нужен плагин DeZog. Подробное описание настроек в [документации плагина](https://github.com/maziac/DeZog/blob/main/documentation/Usage.md#remote-types).
```json
{
"version": "0.2.0",
"configurations": [
{
"type": "dezog",
"request": "launch",
"name": "Simulator",
"remoteType": "zrcp", // используем протокол ZRCP для соединения с okemu
"zrcp": {
"port": 10001, // порт, на котором, по умолчанию, отвечает отладчик okemu
// если эмулятор запущен на другом компьютере, нужно указать его имя или адрес в параметре "host"
},
"sjasmplus": [
{
"path": "main.sld", // файл с символами для отладки, созданный при компиляции
},
// ниже, исходники и файлы для отладки ОС и монитора Океана, если мы хотим видеть их исходный в VSCode в процессе отладки
// их можно убрать. Тогда при трассировке вызовов ОС и монитора мы будем видеть дизасм кода.
{
"path": "cpm/cpm.sld",
"srcDirs": [
"cpm/"
]
},
{
"path": "mon/monitor.sld",
"srcDirs": [
"mon/"
]
}
],
"smartDisassemblerArgs": {
"lowerCase": false
},
"history": {
"reverseDebugInstructionCount": 20, // количество инструкций, которые можно шагнуть назад
"spotCount": 10,
"codeCoverageEnabled": true //true Если мы хотим видеть, какие участки кода нашего приложения выполнялись
},
"startAutomatically": false,
"commandsAfterLaunch": [
//"-rmv", // открыть окно с памятью, на которую указывают 16-разрядные регистры BC,DE,HL,IX,IY
"-mv 0x100 0x80" // открыть окно для просмотра памяти с адреса 100h размером 80h байт
],
"rootFolder": "${workspaceFolder}",
"topOfStack": "stack",
"loadObjs": [
{
"path": "main.obj", // Этот файл будет загружен в эмулятор
"start": "0x0100" // Файл будет загружен с адреса 100h
}
],
"execAddress": "0x0100", // Загруженный код начнет выполняться с адреса 100h
"smallValuesMaximum": 513,
"tmpDir": ".tmp"
}
]
}
```
+9
View File
@@ -0,0 +1,9 @@
{
"recommendations": [
"maziac.asm-code-lens",
"maziac.dezog",
"maziac.hex-hover-converter",
"maziac.z80-instruction-set",
"maziac.sna-fileviewer"
]
}
+60
View File
@@ -0,0 +1,60 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "dezog",
"request": "launch",
"name": "Simulator",
"remoteType": "zrcp",
"zrcp": {
"port": 10001,
},
"sjasmplus": [
{
"path": "main.sld",
},
{
"path": "cpm/cpm.sld",
"srcDirs": [
"cpm/"
]
},
{
"path": "mon/monitor.sld",
"srcDirs": [
"mon/"
]
}
],
"smartDisassemblerArgs": {
"lowerCase": false
},
// "disassemblerArgs": {
// "numberOfLines": 10
// },
"history": {
"reverseDebugInstructionCount": 20,
"spotCount": 10,
"codeCoverageEnabled": true
},
"startAutomatically": false,
"commandsAfterLaunch": [
//"-rmv",
"-mv 0x100 0x80"
],
"rootFolder": "${workspaceFolder}",
"topOfStack": "stack",
"loadObjs": [
{
"path": "main.obj",
"start": "0x0100"
}
],
"execAddress": "0x0100",
"smallValuesMaximum": 513,
"tmpDir": ".tmp"
}
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"mcu-debug.debug-tracker-vscode.debugLevel": 1
}
+23
View File
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "make (sjasmplus)",
"type": "shell",
"command": "sjasmplus",
"args": [
"--i8080",
"--sld=main.sld",
"--raw=main.obj",
"--fullpath",
"--lst",
"main.asm"
],
"problemMatcher": "$problem-matcher-sjasmplus",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
+7
View File
@@ -0,0 +1,7 @@
# Эмулятор персонального компьютера Океан-240.2
Простой пример программы для ОС CP/M.
В папке .vscode прилагаются файлы, необходимые для настройки среды VSCode.
Для компиляции используется [sjasmplus Z80 assembler](https://github.com/z00m128/sjasmplus).
File diff suppressed because it is too large. Load diff
+832
View File
@@ -0,0 +1,832 @@
; =======================================================
; Ocean-240.2
;
; CP/M BIOS
;
; Disassembled by Romych 2025-09-09
; =======================================================
INCLUDE "equates.inc"
INCLUDE "ram.inc"
INCLUDE "mon_entries.inc"
DEFINE CHECK_INTEGRITY
IFNDEF BUILD_ROM
OUTPUT bios.bin
ENDIF
MODULE BIOS
ORG 0xD600
; -------------------------------------------------------
; BIOS JUMP TABLE
; -------------------------------------------------------
boot_f:
JP bios_boot
wboot_f:
JP bios_wboot
; -------------------------------------------------------
; console status to reg-a
; -------------------------------------------------------
const_f:
JP MON.non_con_status
; -------------------------------------------------------
; console character to reg-a
; -------------------------------------------------------
conin_f:
JP MON.mon_con_in
; -------------------------------------------------------
; console character from c to console out
; -------------------------------------------------------
conout_f:
JP MON.mon_con_out
; -------------------------------------------------------
; list device out
; -------------------------------------------------------
list_f:
JP MON.mon_char_print
; -------------------------------------------------------
; punch device out
; -------------------------------------------------------
punch_f:
JP MON.mon_serial_out
; -------------------------------------------------------
; reader character in to reg-a
; -------------------------------------------------------
reader_f:
JP MON.mon_serial_in
; -------------------------------------------------------
; move to home position, treat as track 00 seek
; -------------------------------------------------------
home_f:
JP home
; -------------------------------------------------------
; select disk given by register c
; -------------------------------------------------------
seldsk_f:
JP sel_disk
settrk_f:
JP set_trk
setsec_f:
JP set_sec
; -------------------------------------------------------
; Set DMA address from BC
; -------------------------------------------------------
setdma_f:
JP set_dma
read_f:
JP read
write_f:
JP write
listst_f:
JP list_st
sectran_f:
JP sec_tran
; -------------------------------------------------------
; Reserved
; -------------------------------------------------------
JP warm_boot
JP warm_boot
; -------------------------------------------------------
; Tape read
; -------------------------------------------------------
tape_read_f:
JP MON.mon_tape_read
; -------------------------------------------------------
; Tape write
; -------------------------------------------------------
tape_write_f:
JP MON.mon_tape_write
; -------------------------------------------------------
; Tape wait block
; -------------------------------------------------------
tape_wait_f:
JP MON.mon_tape_wait
JP warm_boot ; r8
disk_a_size DW 192 ; 192k disk A size
disk_b_size DW 720 ; 720 disk B size
disk_c_size DW 720 ; 720 disk C size
disk_b_tracks DB 80
disk_c_tracks DB 80
; -------------------------------------------------------
; cold start
; -------------------------------------------------------
bios_boot:
LD HL, (bdos_ent_addr) ; 0xba06
LD DE, 0x10000-CCP_RAM.bdos_enter_jump ; 0x45fa
ADD HL, DE ; 0xba06+0x45fa=10000
LD A, H
OR L
JP Z, bios_signon
; >> r8
LD HL, (bios_var0) ; if bios_var0 = 0xaaaa (initialized)
LD DE, 0x5556
ADD HL, DE ; 0xaaaa+0x5556=0x10000 if initialized
LD A, H
OR L
JP Z, bios_signon ; if initialized, go to logon, skip init
; <<
; Init DMA buffer
LD HL, dma_buffer ; 0x8000
LD B, DMA_BUFF_SIZE ; 0x80
.init_dma_buff:
LD (HL), FILE_DELETED ; 0xE5
INC HL
DEC B
JP NZ, .init_dma_buff
; Init RAM disk
LD HL, dma_buffer
LD DE, 0x0000
LD B, 8
.init_ram_dsk:
PUSH BC
CALL MON.ram_disk_write
POP BC
INC DE
DEC B
JP NZ, .init_ram_dsk
; Init user to 0 and drive to 0
XOR A
LD (cur_user_drv), A
; init bios variables
CALL bios_init_ilv ; r8
bios_signon:
LD SP, bios_stack
; Print CP/M hello message
LD HL, msg_hello
CALL print_strz
JP bios_wboot
;bios_wboot:
; LD SP, bios_stack
; r8 >>
bios_init_ilv:
LD HL, bios_var0
LD DE, bios_ini_vals
LD C, 13
CALL mov_dlhe_c
LD A, (disk_c_tracks) ; 0x50
LD (disk_c_tracks), A
RET
; <<
; -------------------------------------------------------
; BIOS Warm start entry
; -------------------------------------------------------
bios_wboot: ; r8
LD HL, (bios_var0)
LD DE, 0x5556 ; 0xaaaa + 0x5556 = 0x10000
ADD HL, DE
LD A, H
OR L
CALL NZ, bios_init_ilv ; init if not initialized before
LD SP, bios_stack
; Move CPP from 0xC000 to 0xB200
LD HL, CCP_DST_ADDR
LD DE, CCP_SRC_ADDR
LD BC, CCP_SIZE
.move_ccp:
LD A, (DE)
LD (HL), A
INC DE
INC HL
DEC BC
LD A, B
OR C
JP NZ, .move_ccp
; Init variables with zeroes
LD HL, CPM_VARS.cpm_vars_start
LD BC, CPM_VARS.ccp_vars_size ; 213
.clr_cpm_vars:
LD (HL), 0x0
INC HL
DEC BC
LD A, B
OR C
JP NZ, .clr_cpm_vars
LD A, FILE_DELETED
LD (CPM_VARS.bdos_efcb), A ; mark empty FCB
LD A, low dma_buffer ; 0x80
LD (CPM_VARS.bdos_dmaad), A ; 0x0080
; Move DPH + DPB to RAM
LD HL, CPM_VARS.DPH_RAM
LD DE, dph_disk_a
LD BC, DPB_END-dph_disk_a ; 0x39 -> 57d
.move_dph:
LD A, (DE)
LD (HL), A
INC HL
INC DE
DEC BC
LD A, B
OR C
JP NZ, .move_dph
LD BC, dma_buffer ; DMA default buffer addr
CALL setdma_f
; Setup JP to Warm boot after CPU reset
LD A, JP_OPCODE
LD (warm_boot), A
LD HL, wboot_f
LD (warm_boot_addr), HL
; Setup JP to BDOS entrance
LD (jp_bdos_enter), A
LD HL, CCP_RAM.bdos_enter_jump
LD (bdos_ent_addr), HL
; Disk A
LD HL, CPM_VARS.DPB_A_RAM
LD C, 0xf
LD DE, dpb_ram
LD A, (disk_a_size+1)
OR A
JP Z, .drv_a_192
LD DE, dpb_empty
.drv_a_192:
CALL mov_dlhe_c
; Disk B
LD HL, CPM_VARS.DPB_B_RAM
LD C, 0xf
LD DE, dpb_flop_360k
LD A, (disk_b_size+1)
CP 0x1
JP Z, .drv_b_360
LD DE, dpb_flop_720k
.drv_b_360:
CALL mov_dlhe_c
; Disk C
LD HL, CPM_VARS.DPB_C_RAM
LD C, 0xf
LD A, (disk_c_size+1)
CP 0x2 ; 720?
JP Z, .drv_c_720
LD DE, dpb_flop_360k
; bios_var3 != 0 -> move DPB 360k
LD A, (disk_sw_trk)
OR A
JP NZ, .drv_c_mov
; bios_var3 == 0 -> move DPB 720k
LD DE, dpb_flop_720k
JP .drv_c_mov
.drv_c_720:
LD DE, dpb_flop_720k
; bios_var3 != 0 -> move DPB 720k
LD A, (disk_sw_trk)
OR A
JP NZ, .drv_c_mov
; bios_var3 == 1 -> move DPB 360k
LD DE, dpb_flop_360k
.drv_c_mov:
CALL mov_dlhe_c
XOR A
LD (CPM_VARS.slicer_has_data),A
LD (CPM_VARS.slicer_uninited_count),A
LD A,(cur_user_drv)
LD C,A
; go to CCP
JP CCP_DST_ADDR
; -------------------------------------------------------
; Move C bytes from [DE] to [HL]
; -------------------------------------------------------
mov_dlhe_c:
LD A,(DE) ; [DE]->[HL]
LD (HL),A
INC HL
INC DE
DEC C
JP NZ, mov_dlhe_c
RET
list_st:
XOR A
RET
; -------------------------------------------------------
; Select disk
; Inp: C - disk,
; E - active drive flag
; Out: HL -> DPH
; -------------------------------------------------------
sel_disk:
LD HL, 0x00
LD A, C
CP CTRL_C
RET NC
LD (CPM_VARS.cur_disk), A
OR A
JP Z, .get_dph_addr ; skip next for disk 0 - RAM disk
LD A, E ; selected disk map
AND 0x1 ; bit 0 is set if disk already selected
JP NZ, .get_dph_addr
; Reset disk
LD (CPM_VARS.slicer_has_data), A
LD (CPM_VARS.slicer_uninited_count), A
; calc DPH address of new drive
.get_dph_addr:
LD L, C
LD H, 0x0
ADD HL, HL ; *2
ADD HL, HL ; *4
ADD HL, HL ; *8
ADD HL, HL ; *16 (size of DBH)
LD DE, CPM_VARS.DPH_RAM
ADD HL, DE
RET
; -------------------------------------------------------
; move to track 00
; -------------------------------------------------------
home:
LD A, (CPM_VARS.cur_disk)
OR A
JP Z, .is_default
LD A, (CPM_VARS.slicer_need_save)
OR A
JP NZ, .is_default
LD (CPM_VARS.slicer_has_data), A ; set to 0, no data
.is_default:
LD C, 0 ; set track to 0
; -------------------------------------------------------
; set track address (0..76) for subsequent read/write
; -------------------------------------------------------
set_trk:
LD HL, CPM_VARS.curr_track
LD (HL), C
RET
; -------------------------------------------------------
; set sector address (1,..., 26) for subsequent read/write
; -------------------------------------------------------
set_sec:
LD HL, CPM_VARS.curr_sec
LD (HL), C
RET
; -------------------------------------------------------
; set subsequent dma address (initially 80h)
; -------------------------------------------------------
set_dma:
LD L, C
LD H, B
LD (CPM_VARS.dma_addr), HL
RET
sec_tran:
LD L, C
LD H, B
RET
; -------------------------------------------------------
; read track/sector to preset dma address
; -------------------------------------------------------
read:
LD A, (CPM_VARS.cur_disk)
OR A
JP NZ, read_phys ; for physical disk use special routine
CALL ram_disk_calc_addr
CALL MON.ram_disk_read
XOR A
RET
; -------------------------------------------------------
; write track/sector from preset dma address
; -------------------------------------------------------
write:
LD A, (CPM_VARS.cur_disk)
OR A
JP NZ,write_phys
CALL ram_disk_calc_addr
CALL MON.ram_disk_write
XOR A
RET
; -------------------------------------------------------
; Calculate address for current sector and track
; -------------------------------------------------------
ram_disk_calc_addr:
LD HL, CPM_VARS.curr_track
; HL = cur_track * 16
LD L, (HL)
LD H, 0x0
ADD HL, HL
ADD HL, HL
ADD HL, HL
ADD HL, HL
; DE = HL + cur_sec
EX DE, HL
LD HL, CPM_VARS.curr_sec
LD L, (HL)
LD H, 0x0
ADD HL, DE
EX DE, HL
; store address
LD HL, (CPM_VARS.dma_addr)
RET
read_phys:
CALL read_phys_op
RET
write_phys:
CALL write_phys_op
RET
read_phys_op:
XOR A
; reset counter
LD (CPM_VARS.slicer_uninited_count), A
LD A, 0x1
LD (CPM_VARS.tmp_slicer_operation), A ; 0 - write; 1 - read
LD (CPM_VARS.tmp_slicer_can_read), A ; enable read fron disk
LD A, 0x2
LD (CPM_VARS.tmp_slicer_flush), A ; disable flush data to disk
JP base_read_write
write_phys_op:
XOR A
LD (CPM_VARS.tmp_slicer_operation), A
LD A, C
LD (CPM_VARS.tmp_slicer_flush), A
CP 0x2
JP NZ, .mode_ne_2
LD A, 0x10 ; 2048/128
LD (CPM_VARS.slicer_uninited_count), A
LD A, (CPM_VARS.cur_disk)
LD (CPM_VARS.slicer_uninited_disk), A
LD A, (CPM_VARS.curr_track)
LD (CPM_VARS.slicer_uninited_track), A
LD A, (CPM_VARS.curr_sec)
LD (CPM_VARS.slicer_uninited_sector_128), A
.mode_ne_2:
LD A, (CPM_VARS.slicer_uninited_count)
OR A
JP Z, slicer_read_write
DEC A
LD (CPM_VARS.slicer_uninited_count), A
LD A, (CPM_VARS.cur_disk)
LD HL, CPM_VARS.slicer_uninited_disk
CP (HL)
JP NZ, slicer_read_write
LD A, (CPM_VARS.curr_track)
LD HL, CPM_VARS.slicer_uninited_track
CP (HL)
JP NZ, slicer_read_write
LD A, (CPM_VARS.curr_sec)
LD HL, CPM_VARS.slicer_uninited_sector_128
CP (HL)
JP NZ, slicer_read_write
INC (HL)
LD A, (HL)
CP 36 ; Sectors per track
JP C, .no_inc_track
LD (HL), 0x0
LD A, (CPM_VARS.slicer_uninited_track)
INC A
LD (CPM_VARS.slicer_uninited_track), A
.no_inc_track:
XOR A
LD (CPM_VARS.tmp_slicer_can_read), A
JP base_read_write
; --------------------------------------------------
slicer_read_write:
XOR A
LD (CPM_VARS.slicer_uninited_count), A
INC A
LD (CPM_VARS.tmp_slicer_can_read), A
; --------------------------------------------------
base_read_write:
XOR A
LD (CPM_VARS.tmp_slicer_result), A
LD A, (CPM_VARS.curr_sec)
OR A
RRA
OR A
RRA
LD (CPM_VARS.tmp_slicer_real_sector), A
LD HL, CPM_VARS.slicer_has_data
LD A, (HL)
LD (HL), 0x1
OR A
JP Z, .no_data
LD A, (CPM_VARS.cur_disk)
LD HL, CPM_VARS.slicer_disk
CP (HL)
JP NZ, .pos_diff
LD A, (CPM_VARS.curr_track)
LD HL, CPM_VARS.slicer_track
CP (HL)
JP NZ, .pos_diff
LD A, (CPM_VARS.tmp_slicer_real_sector)
LD HL, CPM_VARS.slicer_real_sector
CP (HL)
JP Z,calc_sec_addr_in_bfr
.pos_diff:
LD A, (CPM_VARS.slicer_need_save)
OR A
CALL NZ, slicer_save_buffer ; save buffer if needed
.no_data:
LD A, (CPM_VARS.cur_disk)
LD (CPM_VARS.slicer_disk), A
LD A, (CPM_VARS.curr_track)
LD (CPM_VARS.slicer_track), A
LD A, (CPM_VARS.tmp_slicer_real_sector)
LD (CPM_VARS.slicer_real_sector), A
LD A, (CPM_VARS.tmp_slicer_can_read)
OR A
CALL NZ,slicer_read_buffer
XOR A
LD (CPM_VARS.slicer_need_save), A
; --------------------------------------------------
calc_sec_addr_in_bfr:
LD A, (CPM_VARS.curr_sec)
AND 0x3
LD L, A
LD H, 0
ADD HL, HL
ADD HL, HL
ADD HL, HL
ADD HL, HL
ADD HL, HL
ADD HL, HL
ADD HL, HL ; *128
LD DE, CPM_VARS.slicer_buffer
ADD HL, DE
EX DE, HL
LD HL, (CPM_VARS.dma_addr)
LD C, 0x80
LD A, (CPM_VARS.tmp_slicer_operation)
OR A
JP NZ, .no_save
LD A, 0x1
LD (CPM_VARS.slicer_need_save), A
EX DE, HL
.no_save:
LD A, (DE)
INC DE
LD (HL), A
INC HL
DEC C
JP NZ, .no_save
LD A, (CPM_VARS.tmp_slicer_flush)
CP 0x1
LD A, (CPM_VARS.tmp_slicer_result)
RET NZ
OR A
RET NZ
XOR A
LD (CPM_VARS.slicer_need_save), A
CALL slicer_save_buffer
LD A, (CPM_VARS.tmp_slicer_result)
RET
; --------------------------------------------------
slicer_save_buffer:
CALL slicer_get_floppy_args
LD C, 0xA6 ; VG93 CMD
CALL MON.write_floppy
LD (CPM_VARS.tmp_slicer_result), A
RET
; --------------------------------------------------
slicer_read_buffer:
CALL slicer_get_floppy_args
LD C, 0x86 ; VG93 CMD
CALL MON.read_floppy
LD (CPM_VARS.tmp_slicer_result), A
RET
; --------------------------------------------------
slicer_get_floppy_args:
LD HL, CPM_VARS.tmp_buff9
LD A, (CPM_VARS.slicer_disk)
DEC A
JP Z, .non_interleave
LD HL, interleave_0
.non_interleave:
LD A, (CPM_VARS.slicer_real_sector)
ADD A, L
LD L, A
LD E, (HL)
LD A, (CPM_VARS.slicer_track)
LD D, A
LD HL, CPM_VARS.slicer_buffer
LD A, (CPM_VARS.slicer_disk)
RET
; -------------------------------------------------------
; Print zerro ended string
; Inp: HL -> string
; -------------------------------------------------------
print_strz:
LD A, (HL)
OR A
RET Z
LD C, A
PUSH HL
CALL conout_f
POP HL
INC HL
JP print_strz
msg_hello:
DB ASCII_ESC, "6", "0" ; 40x25 cursor on
DB ASCII_ESC, "8", "3" ; set palette
DB ASCII_ESC, "5", 33, 37 ; set cursor r,c
DB ASCII_ESC, "4", "1" ; set color
DB ASCII_ESC, "1", 22, 226, 226, 252, 1 ; draw fill rect x1,y1,x2,y2,m
DB ASCII_ESC, "4", "0" ; set color
DB ASCII_ESC, "1", 30, 230, 219, 248, 1 ; draw fill rect x1,y1,x2,y2,m
DB ASCII_ESC, "4", "3" ; set color
DB "OKEAH-240 CP/M (V2.2) REL.8'\r\n\n"
DB ASCII_ESC, "4", "2", 0 ; set color
; --------------------------------------------------
; Disk parameters blocks in ROM (DPBs)
; Tables of memory that describe the characteristics
; of discs on our system. There is one DPB for each
; disc type
; ----------------------------------------
; Block size | No of sectors | BSH | BLM |
; ----------------------------------------
; 1K | 8 | 3 | 7 |
; 2K | 16 | 4 | 15 |
; 4K | 32 | 5 | 31 |
; 8K | 64 | 6 | 63 |
; 16K | 128 | 7 | 127 |
; ----------------------------------------
; -------------------------------------
; Block size| Extent mask (EXM) |
; | Small disk | Large disk |
; -------------------------------------
; 2K | 1 | 0 |
; 4K | 3 | 1 |
; 8K | 7 | 3 |
; 16K | 15 | 7 |
; -------------------------------------
; CKS - number of dir sectors to check before write, 0 for HDD
; For RAM-Disk 192k
dpb_ram:
DW 16 ; SPT Sector (128b) per track (16d)
DB 3 ; BSH 1k
DB 7 ; BLM 1k; Allocation block size = (BLM + 1) * 128 = 1k
DB 0 ; EXM extent mask
DW 191 ; DSM Disk size blocks - 1
DW 31 ; DRM Dir elements - 1
DB 10000000b ; AL0 Dir map byte 1
DB 00000000b ; AL1 Dir map byte 2
DW 0x0008 ; CKS checksum vector size (8 sectors=1k)
DW 0x0000 ; OFF (tracks reserved for system)
dpb_empty:
DS 15, 0xff
; For FLOPPY 720k
dpb_flop_720k:
DW 36 ; SPT Sector (128b) per track 36 * 128 = 18KB
DB 4 ; BSH 2k
DB 15 ; BLM 2k; Allocation block size = (BLM + 1) * 128 = 2k
DB 0 ; EXM extent mask
DW 359 ; DSM Disk size blocks - 1 (359d)
DW 127 ; DRM Directory entries - 1 (127d)
DB 11000000b ; AL0 Dir map byte 1 (2 dir blk)
DB 00000000b ; AL1 Dir map byte 2
DW 32 ; CKS checksum vector size (32 sectors = 2k)
DW 0x0000 ; OFF (No of tracks reserved for system)
; For FLOPPY 360k
dpb_flop_360k:
DW 36 ; SPT Sector (128b) per track 36 * 128 = 18KB
DB 4 ; BSH 2k
DB 15 ; BLM 2k; Allocation block size = (BLM + 1) * 128 = 2k
DB 1 ; EXM extent mask
DW 179 ; DSM Disk size blocks - 1 (179d)
DW 127 ; DRM Directory entries - 1 (127d)
DB 11000000b ; AL0 Dir map byte 1 (2 dir blk)
DB 00000000b ; AL1 Dir map byte 2
DW 32 ; CKS checksum vector size (32 sectors = 2k)
DW 0x0000 ; OFF (No of tracks reserved for system)
bios_ini_vals:
DB 0xaa, 0xaa, 0, 0xff, 1, 8, 6, 4, 2, 9, 7, 5, 3
; --------------------------------------------------
; Disk parameters headers in ROM
; --------------------------------------------------
; Disk A RAM
dph_disk_a:
DW 0 ; Sector translate table pointer
DW 0, 0, 0 ; Scratchpad area
DW CPM_VARS.dir_buffer ; Directory buffer pointer
DW CPM_VARS.DPB_A_RAM ; DPB Pointer
DW CPM_VARS.CHK_VEC_A ; Check Vector pointer
DW CPM_VARS.AL_MAP_A ; Allocation map pointer
; Disk B Floppy
dph_disk_b:
DW 0 ; Sector translate table pointer
DW 0, 0, 0 ; Scratchpad area
DW CPM_VARS.dir_buffer ; Directory buffer pointer
DW CPM_VARS.DPB_B_RAM ; DPB Pointer
DW CPM_VARS.CHK_VEC_B ; Check Vector pointer
DW CPM_VARS.AL_MAP_B ; Allocation map pointer
; Disk C Floppy
dph_disk_c:
DW 0 ; Sector translate table pointer
DW 0, 0, 0 ; Scratchpad area
DW CPM_VARS.dir_buffer ; Directory buffer pointer
DW CPM_VARS.DPB_C_RAM ; DPB Pointer
DW CPM_VARS.CHK_VEC_C ; Check Vector pointer
DW CPM_VARS.AL_MAP_C ; Allocation map pointer
res_data: ; offset 0xda28
DB 1, 8, 6, 4, 2, 9, 7, 5, 3
DPB_END EQU $
DB 0x0e, 3
; -------------------------------------------------------
; Filler to align blocks in ROM
; -------------------------------------------------------
LAST EQU $
CODE_SIZE EQU LAST-0xD600
FILL_SIZE EQU 0x500-CODE_SIZE
DISPLAY "| BIOS\t| ",/H,boot_f," | ",/H,CODE_SIZE," | ",/H,FILL_SIZE," |"
IFDEF CHECK_INTEGRITY
; Check integrity
ASSERT bios_wboot = 0xd6a8
ASSERT sel_disk = 0xd781
ASSERT home = 0xd7a7
ASSERT ram_disk_calc_addr = 0xd7eb
ASSERT write_phys_op = 0xd81e
ASSERT base_read_write = 0xd88a
ASSERT calc_sec_addr_in_bfr = 0xd8e4
ASSERT slicer_save_buffer = 0xd928
ASSERT print_strz = 0xd95e
ASSERT msg_hello = 0xd96b
ASSERT dpb_ram = 0xd9af
ASSERT dph_disk_a = 0xd9f8
ASSERT res_data = 0xda28
ENDIF
FILLER:
DS FILL_SIZE, 0xff
ENDMODULE
IFNDEF BUILD_ROM
OUTEND
ENDIF
File diff suppressed because it is too large. Load diff
+882
View File
@@ -0,0 +1,882 @@
; =======================================================
; Ocean-240.2
; CPM CPP, ROM PART
; AT 0xDB00
;
; Disassembled by Romych 2025-09-09
; =======================================================
INCLUDE "equates.inc"
INCLUDE "ram.inc"
IFNDEF BUILD_ROM
OUTPUT ccp_rom.bin
ENDIF
MODULE CCP_ROM
ORG 0xDB00
@ccp_entry:
LD HL, 0x0 ; prevent stack overflow
ADD HL, SP
LD (CPM_VARS.saved_stack_ptr), HL
LD SP, CPM_VARS.ccp_safe_stack
CALL get_cmd_index
LD HL, ccp_commands ;= DB6Ch
LD E, A
LD D, 0x0
ADD HL, DE
ADD HL, DE
LD A, (HL)
INC HL
LD H, (HL)
LD L, A
JP (HL) ; jump to command
ccp_commands_str:
DB "SDIR READ WRITE"
; -------------------------------------------------------
; Search user command position in available commands list
; -------------------------------------------------------
get_cmd_index:
LD HL, ccp_commands_str ; -> 'DIR'
LD C, 0x0
.cmd_next:
LD A, C
CP CCP_COMMAND_COUNT
RET NC
LD DE, CCP_RAM.ccp_current_fcb_fn
LD B, CCP_COMMAND_SIZE
.cmp_nxt:
LD A, (DE)
CP (HL) ; -> 'DIR'
JP NZ, .no_eq
INC DE
INC HL
DEC B
JP NZ, .cmp_nxt
LD A, (DE)
CP ASCII_SP
JP NZ, .inc_next
LD A, C
RET
.no_eq:
INC HL
DEC B
JP NZ, .no_eq
.inc_next:
INC C
JP .cmd_next
; --------------------------------------------------
; Command handlers ref table
; --------------------------------------------------
ccp_commands:
DW ccp_dir
DW ccp_read
DW ccp_write
DW ccp_ret ; r8
; DW ccp_exit1 ; r8
ccp_ret:
LD HL, (CPM_VARS.saved_stack_ptr)
LD SP, HL
JP CCP_RAM.ccp_unk_cmd
;ccp_exit1:
; JP MON.mon_hexb
; --------------------------------------------------
; DIR [filemask] command handler
; --------------------------------------------------
ccp_dir:
CALL CCP_RAM.ccp_cv_first_to_fcb
CALL CCP_RAM.ccp_drive_sel
; chech some filemask specified in command line
LD HL, CCP_RAM.ccp_current_fcb_fn
LD A, (HL)
CP ' '
JP NZ, .has_par
; no filemask, fill with wildcard '?'
LD B, 11
.fill_wildcard:
LD (HL), '?'
INC HL
DEC B
JP NZ, .fill_wildcard
; find file by specified mask
.has_par:
CALL CCP_RAM.ccp_find_first
JP NZ, .f_found
; no files found, print and exit
CALL CCP_RAM.ccp_out_no_file
JP CCP_RAM.ccp_cmdline_back
.f_found:
CALL CCP_RAM.ccp_out_crlf
LD HL, 0x0
LD (CPM_VARS.tmp_dir_total), HL
LD E, 0
.do_next_direntry:
PUSH DE
CALL CCP_RAM.ccp_find_first
POP DE
PUSH DE
; Find file with e number
.find_file_e:
DEC E
JP M, .file_out_next
PUSH DE
CALL CCP_RAM.ccp_bdos_find_next
POP DE
JP Z, .file_e_found
JP .find_file_e
.file_out_next:
LD A, (CCP_RAM.ccp_bdos_result_code)
; calc address of DIR entry in DMA buffer
; A[6:5] = A[1:0] = 32*A
RRCA ; [C] -> [7:0] -> [C]
RRCA ;
RRCA ;
AND 01100000b ; mask
LD C, A
PUSH BC
CALL CCP_RAM.ccp_out_crlf ; start new line
CALL CCP_RAM.ccp_bdos_drv_get
INC A
LD (dma_buffer), A ; disk
POP BC
LD B, 0x0
LD HL, dma_buffer+FCB_FN ; filename
LD E, L
LD D, H
ADD HL, BC
; copy filename to tmp FCB and out to screen
LD B, 0x1
.copy_next:
LD A, (HL)
LD (DE), A
LD C, A
CALL BIOS.conout_f
INC HL
INC DE
INC B
LD A, B
CP FN_LEN ; >12 end of name
JP C, .copy_next
.zero_up_36:
XOR A
LD (DE), A ; zero at end
INC B
LD A, B
CP 36
JP C, .zero_up_36
; calc file size for current entry
LD DE, dma_buffer
CALL cpp_bdos_f_size
LD HL, (fcb_ra_record_num) ; file size in blocks
; get disk blk size
LD A, (CPM_VARS.bdos_curdsk)
OR A
JP NZ, .no_dsk_a0
LD B, 3 ; for A - blk=3
JP .dsk_a0
.no_dsk_a0:
LD B, 4 ; for other disks - blk=4
.dsk_a0:
LD C, L
; convert 128b OS block to disk blocks
.mul_to_dsk_blk:
XOR A
LD A, H
RRA
LD H, A
LD A, L
RRA
LD L, A
DEC B
JP NZ, .mul_to_dsk_blk
; round up
LD A, (CPM_VARS.bdos_curdsk)
OR A
JP NZ, .no_dsk_a1
LD A, 00000111b ; for A - ~(~0 << 3)
JP .ds_skip1
.no_dsk_a1:
LD A, 00001111b ; for other dsk - ~(~0 << 4)
.ds_skip1:
AND C
JP Z, .cvt_blk_kb
INC HL
; Convert blocks to kilobytes (A-1k B-2k)
.cvt_blk_kb:
LD A, (CPM_VARS.bdos_curdsk)
OR A
JP Z, .ds_skip2
ADD HL, HL ; 2k
; add file size to total dir size
.ds_skip2:
EX DE, HL
LD HL, (CPM_VARS.tmp_dir_total)
ADD HL, DE
LD (CPM_VARS.tmp_dir_total), HL
; display size in K
LD C, ' '
CALL BIOS.conout_f
CALL BIOS.conout_f
CALL ccp_cout_num
LD C, 'K'
CALL BIOS.conout_f
CALL CCP_RAM.ccp_getkey_no_wait
JP NZ, CCP_RAM.ccp_cmdline_back
POP DE
INC E
JP .do_next_direntry
.file_e_found:
POP DE
LD HL, msg_free_space ;= "\r\nFREE SPACE "
; Out: FREE SPACE
CALL ccp_out_str_z
LD A, (CPM_VARS.bdos_curdsk)
OR A
JP NZ, .no_ram_dsk
LD HL, (BIOS.disk_a_size)
JP .calc_remanis_ds
.no_ram_dsk:
DEC A
LD HL, (BIOS.disk_b_size)
JP Z, .calc_remanis_ds
LD HL, (BIOS.disk_c_size)
LD A, (disk_sw_trk)
OR A
JP NZ, .calc_remanis_ds
LD A, H
CP 1
JP Z, .d720
LD HL, 360
JP .calc_remanis_ds
.d720:
LD HL, 720
; Disk size - Dir size = Free
.calc_remanis_ds:
EX DE, HL
LD HL, (CPM_VARS.tmp_dir_total)
LD A, E
SUB L
LD E, A
LD A, D
SBC A, H
LD D, A
CALL ccp_cout_num
LD C, 'K'
CALL BIOS.conout_f
CALL CCP_RAM.ccp_out_crlf
JP CCP_RAM.ccp_cmdline_back
msg_free_space:
DB "\r\nFREE SPACE ",0
ccp_cout_num:
LD A, D
AND 11100000b
JP Z, .less_224
LD C, '*'
CALL BIOS.conout_f
CALL BIOS.conout_f
CALL BIOS.conout_f
CALL BIOS.conout_f
RET
.less_224:
LD HL, 0x0
; copy number to BC
LD B, D
LD C, E
LD DE, 0x1
LD A, 13
.bc_rra:
PUSH AF
PUSH HL
; BC >> 1
LD A, B
RRA
LD B, A
LD A, C
RRA
LD C, A
JP NC, .bc_rra_ex
POP HL
CALL cpp_daa16
PUSH HL
.bc_rra_ex:
LD L, E
LD H, D
CALL cpp_daa16
EX DE, HL
POP HL
POP AF
DEC A
JP NZ, .bc_rra
LD D, 4
LD B, 0
.next_d:
LD E, 4
.next_e:
LD A, L
RLA
LD L, A
LD A, H
RLA
LD H, A
LD A, C
RLA
LD C, A
DEC E
JP NZ, .next_e
LD A, C
AND 0xf
ADD A, '0'
CP '0'
JP NZ, .no_zero
DEC B
INC B
JP NZ, .b_no_one
LD A, D
DEC A
JP Z, .d_one
LD A, ' '
JP .b_no_one
.d_one:
LD A, '0'
.no_zero:
LD B, 0x1
.b_no_one:
LD C, A
CALL BIOS.conout_f
DEC D
JP NZ, .next_d
RET
; -------------------------------------------------------
; ADD with correction HL=HL+DE
; -------------------------------------------------------
cpp_daa16:
LD A, L
ADD A, E
DAA
LD L, A
LD A, H
ADC A, D
DAA
LD H, A
RET
; -------------------------------------------------------
; Call BDOS function 35 (F_SIZE) - Compute file size
; -------------------------------------------------------
cpp_bdos_f_size:
LD C, F_SIZE
JP jp_bdos_enter
; -------------------------------------------------------
; Read Intel HEX data from serial port
; -------------------------------------------------------
ccp_read:
LD DE, msg_read_hex
CALL out_dollar_str
LD HL, 0x0
LD (CCP_RAM.hex_length), HL
; Wait for start of Intel HEX line
.wait_colon:
CALL MON.mon_serial_in
CP ':'
JP NZ, .wait_colon
; Init checksum
XOR A
LD D, A
CALL ser_read_hexb ; read byte_count
JP Z, .end_of_file
LD E, A
CALL ser_read_hexb ; read address hi
LD H, A
CALL ser_read_hexb ; read address lo
LD L, A ; HL - dst address
CALL ser_read_hexb ; read rec type
; calculate length += byte_count
PUSH HL
LD HL, (CCP_RAM.hex_length)
LD A, L
ADD A, E
LD L, A
LD A, H
ADC A, 0
LD H, A
LD (CCP_RAM.hex_length), HL
POP HL
LD C, E
; receive next E=byte_count bytes
.receive_rec:
CALL ser_read_hexb
LD (HL), A
INC HL
DEC E
JP NZ, .receive_rec
CALL ser_read_hexb ; receive checksum
JP NZ, .load_error ; jump if error
JP .wait_colon ; jump to wait next line
.end_of_file:
; read tail 4 bytes: 00 00 01 ff
CALL ser_read_hexb
CALL ser_read_hexb
CALL ser_read_hexb
CALL ser_read_hexb
JP Z, .load_complete
.load_error:
LD DE, .msg_error
JP out_dollar_str
.load_complete:
; Out message with length of received file
LD HL, (CCP_RAM.hex_length)
LD A, H
CALL MON.mon_hexb
LD A, L
CALL MON.mon_hexb
LD DE, .msg_bytes
CALL out_dollar_str
; Calculate number of pages
LD HL, (CCP_RAM.hex_length)
LD A, L
ADD A, 0xff
LD A, H
ADC A, 0x0
RLA
LD (CCP_RAM.hex_sectors), A
; Out message with number of pages
CALL MON.mon_hexb
LD DE, .msg_pages
CALL out_dollar_str
; Check for file name specified in cmd line
CALL CCP_RAM.ccp_cv_first_to_fcb
CALL CCP_RAM.ccp_drive_sel
LD A, (CCP_RAM.ccp_current_fcb_fn)
CP ASCII_SP
JP Z, .warm_boot
; Create file
LD DE, CCP_RAM.ccp_current_fcb
LD C, F_MAKE
CALL jp_bdos_enter
INC A
JP Z, .load_error
LD HL, tpa_start
LD (CCP_RAM.hex_buff), HL
.wr_sector:
; set source buffer address
LD HL, (CCP_RAM.hex_buff)
EX DE, HL
LD C, F_DMAOFF
CALL jp_bdos_enter
; write source buffer to disk
LD DE, CCP_RAM.ccp_current_fcb
LD C, F_WRITE
CALL jp_bdos_enter
; check errors
OR A
JP NZ, .load_error
; rewind forward to next sector
LD HL, (CCP_RAM.hex_buff)
LD DE, 128 ; sector size
ADD HL, DE
LD (CCP_RAM.hex_buff), HL
; decrement sector count
LD A, (CCP_RAM.hex_sectors)
DEC A
LD (CCP_RAM.hex_sectors), A
JP NZ, .wr_sector ; jump if remains sectors
; close file
LD DE, CCP_RAM.ccp_current_fcb
LD C, F_CLOSE
CALL jp_bdos_enter
; check errors
CP 0xff
JP Z, .load_error
.warm_boot:
LD C, P_TERMCPM
JP jp_bdos_enter
.msg_bytes:
DB "h bytes ($"
.msg_pages:
DB " pages)\n\r$"
.msg_error:
DB "error!\n\r$"
; ---------------------------------------------------
; Read next two symbols from serial and convert to
; byte
; Out: A - byte
; CF set if error
; ---------------------------------------------------
ser_read_hexb:
PUSH BC
CALL MON.mon_serial_in
CALL hex_to_nibble
RLCA
RLCA
RLCA
RLCA
LD C, A
CALL MON.mon_serial_in
CALL hex_to_nibble
OR C
LD C, A
ADD A, D
LD D, A
LD A, C
POP BC
RET
; ---------------------------------------------------
; Convert hex symbol to byte
; Inp: A - '0'..'F'
; Out: A - 0..15
; CF set if error
; ---------------------------------------------------
hex_to_nibble:
SUB '0' ; < '0' - error
RET C
ADD A, 233 ; F -> 255
RET C ; > F - error
ADD A, 6
JP P, .l1
ADD A, 7
RET C
.l1:
ADD A, 10
OR A
RET
; ---------------------------------------------------
; Out $ ended string
; Inp: DE -> string$
; ---------------------------------------------------
out_dollar_str:
LD C, C_WRITESTR
JP jp_bdos_enter
msg_read_hex:
DB "\n\rRead HEX from RS232... $"
filler1:
DS 62, 0
; -------------------------------------------------------
; Out zerro ended string
; In: HL -> strZ
; -------------------------------------------------------
ccp_out_str_z:
LD A, (HL)
OR A
RET Z
LD C, A
CALL BIOS.conout_f
INC HL
JP ccp_out_str_z
; -------------------------------------------------------
; Delete file and out No Space message
; -------------------------------------------------------
ccp_del_f_no_space:
LD DE, CCP_RAM.ccp_current_fcb
CALL CCP_RAM.ccp_bdos_era_file
JP CCP_RAM.ccp_no_space
; -------------------------------------------------------
; Read current file next block
; Out: A=0 - Ok, 0xFF - HW Error;
; -------------------------------------------------------
cpp_read_f_blk:
LD DE, CPM_VARS.ccp_fcb ; FCB here
JP CCP_RAM.ccp_bdos_read_f
ccp_write:
CALL CCP_RAM.ccp_cv_first_to_fcb
CALL CCP_RAM.ccp_drive_sel
LD HL, CCP_RAM.ccp_current_fcb_fn
LD A, (HL)
CP ' '
JP NZ, .find_f
LD B, 11
.fill_with_wc:
LD (HL), '?'
INC HL
DEC B
JP NZ, .fill_with_wc
.find_f:
CALL CCP_RAM.ccp_find_first
JP NZ, .found_f
CALL CCP_RAM.ccp_out_no_file
JP CCP_RAM.ccp_cmdline_back
.found_f:
LD E, 0 ; file counter
.do_next_f1:
PUSH DE
CALL CCP_RAM.ccp_find_first
POP DE
PUSH DE
.do_next_f2:
DEC E
JP M, .do_file
PUSH DE
CALL CCP_RAM.ccp_bdos_find_next
POP DE
JP Z, .no_more_f
JP .do_next_f2
.do_file:
POP BC
PUSH BC
LD A, C
OR A
JP Z, .calc_addr
LD DE, 1200
; Delay with key interrupt check
.delay_1:
XOR A
.delay_2:
DEC A
JP NZ, .delay_2
PUSH DE
CALL CCP_RAM.ccp_getkey_no_wait
POP DE
JP NZ, CCP_RAM.ccp_cmdline_back
DEC DE
LD A, D
OR E
JP NZ, .delay_1
.calc_addr:
LD A, (CCP_RAM.ccp_bdos_result_code)
; A=0-3 - for Ok, calc address of DIR entry in DMA buffer
RRCA
RRCA
RRCA
AND 01100000b
LD C, A
PUSH BC
CALL CCP_RAM.ccp_out_crlf
CALL CCP_RAM.ccp_bdos_drv_get
INC A
LD (CPM_VARS.ccp_fcb_dr), A ; set drive number
POP BC
LD B, 0x0
LD HL, dma_buffer+1
ADD HL, BC
LD DE, CPM_VARS.ccp_fcb_fn
LD B, 0x1
.copy_fn:
LD A, (HL)
LD (DE), A
INC HL
INC DE
INC B
LD A, B
CP 12
JP C, .copy_fn
.fillz_fn:
XOR A
LD (DE), A
INC DE
INC B
LD A, B
CP 36
JP C, .fillz_fn
LD HL, CPM_VARS.ccp_fcb_fn
CALL ccp_out_str_z
LD HL, dma_buffer
; Empty first 128 bytes of DMA buffer
LD B, 128
.clear_buf:
LD (HL), 0x0
INC HL
DEC B
JP NZ, .clear_buf
; Copy file name at buffer start
LD HL, dma_buffer
LD DE, CPM_VARS.ccp_fcb_fn
LD B, 8
.find_sp:
LD A, (DE)
CP ' '
JP Z, .sp_rep_dot ; ' ' -> '.'
LD (HL), A
INC HL
INC DE
JP .find_sp
.sp_rep_dot:
LD (HL), '.'
INC HL
CALL CCP_RAM.ccp_find_no_space
.cont_copy_fn:
LD A, (DE)
LD (HL), A
OR A
JP Z, .end_copy
INC HL
INC DE
JP .cont_copy_fn
.end_copy:
LD DE, CPM_VARS.ccp_fcb
CALL CCP_RAM.ccp_bdos_open_f
LD DE, 0x8000 ; Block ID
LD HL, dma_buffer
CALL cpp_pause_tape_wr_blk
CALL cpp_pause_tape_wr_blk
LD DE, 0x1
; Read file block and write to Tape
.read_f_write_t:
PUSH DE
CALL cpp_read_f_blk
; a=0xff if error; a=1 - EOF
DEC A
JP Z, .eof
LD A, (CPM_VARS.ccp_fcb_cr)
AND 0x7f
CP 0x1
JP NZ, .write_once
; Write block to Tape with ID=0 twice
LD DE, 0x0 ; Block ID=0
LD HL, dma_buffer
CALL cpp_pause_tape_wr_blk
.write_once:
CALL CCP_RAM.ccp_getkey_no_wait
LD HL, dma_buffer
POP DE
JP NZ, CCP_RAM.ccp_cmdline_back
CALL cpp_pause_tape_wr_blk
; Inc Block ID and continue
INC DE
JP .read_f_write_t
.eof:
POP DE
EX DE, HL
LD (dma_buffer), HL
EX DE, HL
; Final block ID=0xFFFF
LD DE, 0xffff
; Write twice
CALL cpp_pause_tape_wr_blk
CALL cpp_pause_tape_wr_blk
POP DE
INC E
JP .do_next_f1
.no_more_f:
POP DE
CALL CCP_RAM.ccp_out_crlf
JP CCP_RAM.ccp_cmdline_back
; -------------------------------------------------------
; Write block to tape after pause
; -------------------------------------------------------
cpp_pause_tape_wr_blk:
LD BC, 3036
.delay:
DEC BC
LD A, B
OR C
JP NZ, .delay
JP BIOS.tape_write_f
DB 0x4c
; -------------------------------------------------------
; Filler to align blocks in ROM
; -------------------------------------------------------
LAST EQU $
CODE_SIZE EQU LAST-0xDB00
FILL_SIZE EQU 0x500-CODE_SIZE
DISPLAY "| CCP_ROM\t| ",/H,ccp_entry," | ",/H,CODE_SIZE," | ",/H,FILL_SIZE," |"
; Check integrity
ASSERT ccp_dir = 0xdb62
ASSERT ccp_dir.find_file_e = 0xdb97
ASSERT ccp_dir.file_out_next = 0xdba6
ASSERT ccp_dir.file_e_found = 0xdc3e
ASSERT ccp_dir.calc_remanis_ds = 0xdc72
ASSERT ccp_dir.no_ram_dsk = 0xdc52
ASSERT msg_free_space = 0xdc8a
ASSERT ccp_cout_num = 0xdc9a
FILLER
DS FILL_SIZE-1, 0xff
DB 0xaa
ENDMODULE
IFNDEF BUILD_ROM
OUTEND
ENDIF
+46
View File
@@ -0,0 +1,46 @@
; ======================================================
; Ocean-240.2
; CP/M Combine file. Includes all sources to build
; ROM 0xC000
;
; Disassembled by Romych 2025-02-12
; ======================================================
DEFINE BUILD_ROM
DEVICE NOSLOT64K
;
; |-----------|---------------|-----------|--------------------------------------|
; | OFFSET | SIZE | Module | Memory Address |
; |-----------|---------------|-----------|--------------------------------------|
; | 0x0000 | 2048 (0x800) | CCP_RAM | 0xC000..0xC7FF -> RAM 0xB200..0xB5FF |
; | 0x0800 | 3584 (0xE00) | BDOS | 0xC800.. |
; | 0x1600 | 1024 (0x400) | BIOS | 0xD600..D9FF |
; | 0x1B00 | 1280 (0x500) | CCP_ROM | 0xDB00..DFFF |
; |-----------|---------------|-----------|--------------------------------------|
;
DISPLAY "| Module | Offset | Size | Free |"
DISPLAY "|-------------|---------|--------|--------|"
OUTPUT cpm-C000.bin
;LABELSLIST "cpm.labels"
;CSPECTMAP "cpm.map"
INCLUDE "equates.inc"
INCLUDE "bdos.inc"
INCLUDE "ccp_ram.asm"
INCLUDE "bdos.asm"
INCLUDE "bios.asm"
INCLUDE "ccp_rom.asm"
OUTEND
OUTPUT variables.bin
INCLUDE "cpm_vars.inc"
OUTEND
END
File diff suppressed because it is too large. Load diff
+43
View File
@@ -0,0 +1,43 @@
; ==================================================
; Simple CP/M program
; By Romych
; ==================================================
DEVICE NOSLOT64K
SLDOPT COMMENT WPMEM, ASSERTION, LOGPOINT
; INCLUDE "ok240/equates.inc"
INCLUDE "ok240/bdos.inc"
OUTPUT main.com
ORG 0x100
LD B, 10
LD SP, stack
AGAIN:
LD DE, message
; ASSERTION B < 11
LD A, 10
SUB B
OR 0x30
LD (DE), A
LD C, C_WRITESTR
PUSH BC
CALL BDOS_ENTER
POP BC
DEC B ; LOGPOINT
JP NZ, AGAIN
JP WARM_BOOT
message: ; WPMEM, 1, w
DB "n - Welcome to OK240.2!\r\n$"
OUTEND
;DS 1024
stack EQU 0xbfc0
;DISPLAY "message: EQU\t| ",/H,message
END
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+73
View File
@@ -0,0 +1,73 @@
; =======================================================
; Ocean-240.2
; CP/M v2.2. Equates to call BDOS functions
;
; Created by Romych 2026-02-16
; =======================================================
IFNDEF _BDOS_INC
DEFINE _BDOS_INC
; ------------------------------------------------------
; CP/M Entries and variables
; ------------------------------------------------------
WARM_BOOT EQU 0x0000 ; Jump warm_boot (Restart)
IO_BYTE EQU 0x0003 ; Input/Output mapping
CUR_USER_DRV EQU 0x0004 ; [7:4] - curent user, [3:0] - current drive
BDOS_ENTER EQU 0x0005 ; Jump bdos (CALL 5 to make CP/M requests)
FCB1 EQU 0x005c ; Default FCB, 16 bytes
FCB2 EQU 0x006c
DMA_BUFFER EQU 0x0080 ; Default "DMA" 128 bytes buffer
CMD_LINE_LEN EQU 0x0080 ; command line character count
CMD_LINE EQU 0x0081 ; command line buffer
TPA EQU 0x0100 ; start of program
; ------------------------------------------------------
; CP/M BDOS Functions
; ------------------------------------------------------
P_TERMCPM EQU 0 ; System Reset
C_READ EQU 1 ; Console input
C_WRITE EQU 2 ; Console output
A_READ EQU 3 ; Auxiliary (Reader) input
A_WRITE EQU 4 ; Auxiliary (Punch) output
L_WRITE EQU 5 ; Printer output
C_RAWIO EQU 6 ; Direct console I/O
A_STATIN EQU 7 ; Auxiliary Input status
A_STATOUT EQU 8 ; Auxiliary Output status
C_WRITESTR EQU 9 ; Output string
C_READSTR EQU 10 ; Buffered console input
C_STAT EQU 11 ; Console status
S_BDOSVER EQU 12 ; Return version number
DRV_ALLRESET EQU 13 ; Reset discs
DRV_SET EQU 14 ; Select disc
F_OPEN EQU 15 ; Open file
F_CLOSE EQU 16 ; Close file
F_SFIRST EQU 17 ; search for first
F_SNEXT EQU 18 ; search for next
F_DELETE EQU 19 ; delete file
F_READ EQU 20 ; read next record
F_WRITE EQU 21 ; write next record
F_MAKE EQU 22 ; create file
F_RENAME EQU 23 ; Rename file
DRV_LOGINVEC EQU 24 ; Return bitmap of logged-in drives
DRV_GET EQU 25 ; Return current drive
F_DMAOFF EQU 26 ; Set DMA address
DRV_ALLOCVEC EQU 27 ; Return address of allocation map
DRV_SETRO EQU 28 ; Software write-protect current disc
DRV_ROVEC EQU 29 ; Return bitmap of read-only drives
F_ATTRIB EQU 30 ; set file attributes
DRV_DPB EQU 31 ; get DPB address
F_USERNUM EQU 32 ; get/set user number
F_READRAND EQU 33 ; Random access read record
F_WRITERAND EQU 34 ; Random access write record
F_SIZE EQU 35 ; Compute file size
F_RANDREC EQU 36 ; Update random access pointer
DRV_RESET EQU 37 ; Selectively reset disc drives
DRV_ACCESS EQU 38 ; Access drives
DRV_FREE EQU 39 ; Free drive
F_WRITEZF EQU 40 ; Write random with zero fill
ENDIF
+104
View File
@@ -0,0 +1,104 @@
; ======================================================
; Ocean-240.2
; Equates for all assembly sources
;
; By Romych 2026-03-10
; ======================================================
IFNDEF _EQUATES
DEFINE _EQUATES
ASCII_BELL EQU 0x07 ; Make Beep
ASCII_BS EQU 0x08 ; Move cursor left (Back Space)
ASCII_TAB EQU 0x09 ; Move cursor right +8 pos
ASCII_LF EQU 0x0A ; Move cursor down (Line Feed)
ASCII_FF EQU 0x0C ; Move cursor to home (Form Feed)
ASCII_CR EQU 0x0D ; Move gursor to 1st pos (Cariage Return)
ASCII_CAN EQU 0x18 ; Move cursor right
ASCII_EM EQU 0x19 ; Move cursor up
ASCII_SUB EQU 0x1A ; CTRL-Z - end of text file marker
ASCII_ESC EQU 0x1B ;
ASCII_US EQU 0x1F ; Clear screen
ASCII_SP EQU 0x20
ASCII_DEL EQU 0x7F
; ------------------------------------------------------
BELL_PIN EQU 0x08 ; DD67 Pin PC3 - "BELL"
; ------------------------------------------------------
CTRL_A EQU 0x01
CTRL_B EQU 0x02
CTRL_C EQU 0x03 ; Warm boot
CTRL_D EQU 0x04
CTRL_E EQU 0x05 ; Move to beginning of new line (Physical EOL)
CTRL_F EQU 0x06
CTRL_G EQU 0x07
CTRL_H EQU 0x08 ; Backspace
CTRL_I EQU 0x09
CTRL_J EQU 0x0A ; LF - Line Feed
CTRL_K EQU 0x0B
CTRL_L EQU 0x0C
CTRL_M EQU 0x0D ; CR - Carriage Return
CTRL_N EQU 0x0E
CTRL_O EQU 0x0F
CTRL_P EQU 0x10 ; turn on/off printer
CTRL_Q EQU 0x11
CTRL_R EQU 0x12 ; Repeat current cmd line
CTRL_S EQU 0x13 ; Temporary stop display data to console (aka DC3)
CTRL_T EQU 0x14
CTRL_U EQU 0x15 ; Cancel (erase) current cmd line
CTRL_V EQU 0x16
CTRL_W EQU 0x17
CTRL_X EQU 0x18 ; Cancel (erase) current cmd line
CTRL_Y EQU 0x19
CTRL_Z EQU 0x1A ; CTRL-Z - end of text file marker
; ------------------------------------------------------
TRUE EQU 0xFF
FALSE EQU 0x00
; ---------------------------------------------------
; FCB Offsets
; ---------------------------------------------------
FCB_LEN EQU 32 ; length of FCB
FCB_SHF EQU 5
FN_LEN EQU 12 ; Length of filename in FCB
FCB_DR EQU 0 ; Drive. 0 for default, 1-16 for A-P
FCB_FN EQU 1 ; Fn - Filename, 7-bit ASCII. The top bits - attributes
FCB_FT EQU 9 ; Filetype, 7-bit ASCII.
; T1' to T3' have the following
; T1' - Read-Only
; T2' - System (hidden)
; T3' - Archive
FCB_EXT EQU 12 ; EX - Set this to 0 when opening a file and then leave it to
; CP/M. You can rewind a file by setting EX, RC, S2 and CR to 0.
FCB_S1 EQU 13 ; S1 - Reserved.
FCB_S2 EQU 14 ; S2 - Reserved. Bit 7 - wile write flag, [6:0] module number (Extent hi bits)
FCB_RC EQU 15 ; RC - Set this to 0 when opening a file and then leave it to CP/M.
FCB_AL EQU 16 ; AL - Image of the second half of the directory entry,
; containing the file's allocation (which disc blocks it owns).
FCB_CR EQU 32 ; CR - Current record within extent. It is usually best to set
; this to 0 immediately after a file has been opened and
; then ignore it.
FCB_RN EQU 33 ; Rn - Random access record number. A 16-bit (with R2 used for overflow)
; ------------------------------------------------------
IRQ_0 EQU 0x01
IRQ_1 EQU 0x02
IRQ_2 EQU 0x04
IRQ_KEYBOARD EQU 0x02
IRQ_PRINTER EQU 0x08
IRQ_TIMER EQU 0x10
KBD_ACK EQU 0x10
PRINTER_ACK EQU 0x10
TX_READY EQU 0x01
RX_READY EQU 0x02
TMR0_SQWAVE EQU 0x36
; ------------------------------------------------------
ENDIF
+132
View File
@@ -0,0 +1,132 @@
; =======================================================
; Ocean-240.2
; Computer with FDC variant.
; IO Ports definitions
;
; By Romych 2025-09-09
; =======================================================
IFNDEF _IO_PORTS
DEFINE _IO_PORTS
; -------------------------------------------------------
; КР580ВВ55 DD79
; -------------------------------------------------------
; Port A - User port A
USR_DD79PA EQU 0x00
; Port B - User port B
USR_DD79PB EQU 0x01
; Port C - User port C
USR_DD79PC EQU 0x02
; Config: [1][ma1,ma0][0-aO|1-aI],[0-chO,1-chI],[mb],[0-bO|1-bI],[0-clO,1-clI]
; Set bit: [0][xxx][bbb][0|1]
USR_DD79CTR EQU 0x03
; -------------------------------------------------------
; КР1818ВГ93
; -------------------------------------------------------
; CMD
FDC_CMD EQU 0x20
; TRACK
FDC_TRACK EQU 0x21
; SECTOR
FDC_SECT EQU 0x22
; DATA
FDC_DATA EQU 0x23
;
FDC_DRQ EQU 0x24
; Controller port
FLOPPY EQU 0x25
; -------------------------------------------------------
; КР580ВВ55 DD78
; -------------------------------------------------------
; Port A - Keyboard Data
KBD_DD78PA EQU 0x40
; Port B - JST3,SHFT,CTRL,ACK,TAPE5,TAPE4,GK,GC
KBD_DD78PB EQU 0x41
; Port C - [PC7..0]
KBD_DD78PC EQU 0x42
; Сonfig: [1][ma1,ma0][0-aO|1-aI],[0-chO,1-chI],[mb],[0-bO|1-bI],[0-clO,1-clI]
; Set bit: [0][xxx][bbb][0|1];
KBD_DD78CTR EQU 0x43
; -------------------------------------------------------
; КР580ВИ53 DD70
; -------------------------------------------------------
; Counter 1
TMR_DD70C1 EQU 0x60
; Counter 2
TMR_DD70C2 EQU 0x61
; Counter 3
TMR_DD70C3 EQU 0x62
; Config: [sc1,sc0][rl1,rl0][m2,m1,m0][bcd]
; sc - timer, rl=01-LSB, 10-MSB, 11-LSB+MSB
; mode 000 - int on fin,
; 001 - one shot,
; x10 - rate gen,
; x11-sq wave
TMR_DD70CTR EQU 0x63
; Programable Interrupt controller PIC KR580VV59
PIC_DD75A EQU 0x80
PIC_DD75B EQU 0x81
; -------------------------------------------------------
; КР580ВВ51 DD72
; -------------------------------------------------------
; Data
UART_DD72RD EQU 0xA0
; [RST,RQ_RX,RST_ERR,PAUSE,RX_EN,RX_RDY,TX_RDY]
UART_DD72RR EQU 0xA1
; -------------------------------------------------------
; КР580ВВ55 DD17
; -------------------------------------------------------
; Port A - VShift[8..1]
SYS_DD17PA EQU 0xC0
; Port B - [ROM14,13][REST][ENROM-][A18,17,16][32k]
SYS_DD17PB EQU 0xC1
; Port C - HShift[HS5..1,SB3..1]
SYS_DD17PC EQU 0xC2
; Сonfig: [1][ma1,ma0][0-aO|1-aI],[0-chO,1-chI],[mb],[0-bO|1-bI],[0-clO,1-clI]
; Set bit: [0][xxx][bbb][0|1];
SYS_DD17CTR EQU 0xC3
; -------------------------------------------------------
; КР580ВВ55 DD67
; -------------------------------------------------------
; Port A - LPT Data
LPT_DD67PA EQU 0xE0
; Port B - [VSU,C/M,FL3..1,COL3..1]
VID_DD67PB EQU 0xE1
; Port C - [USER3..1,STB-LP,BELL,TAPE3..1]
DD67PC EQU 0xE2
; Сonfig: [1][ma1,ma0][0-aO|1-aI],[0-chO,1-chI],[mb],[0-bO|1-bI],[0-clO,1-clI]
; Set bit: [0][xxx][bbb][0|1];
DD67CTR EQU 0xE3
ENDIF
+31
View File
@@ -0,0 +1,31 @@
; =======================================================
; Ocean-240.2
; Equates to call Monitor v8 functions
;
; Created by Romych 2026-02-16
; =======================================================
IFNDEF _MON_INC
DEFINE _MON_INC
mon_start EQU 0xE000
mon_hexb EQU 0xE003
non_con_status EQU 0xE006
mon_con_in EQU 0xE009
mon_con_out EQU 0xE00C
mon_serial_in EQU 0xE00F
mon_serial_out EQU 0xE012
mon_char_print EQU 0xE015
mon_tape_read EQU 0xE018
mon_tape_write EQU 0xE01B
mon_ram_disk_read EQU 0xE01E
mon_ram_disk_write EQU 0xE021
mon_tape_read_ram EQU 0xE024
mon_tape_write_ram EQU 0xE027
mon_tape_wait EQU 0xE02A
mon_tape_detect EQU 0xE02D
mon_read_floppy EQU 0xE030
mon_write_floppy EQU 0xE033
mon_out_str_z EQU 0xE036
ENDIF
+41
View File
@@ -0,0 +1,41 @@
; =======================================================
; Ocean-240.2
;
; RAM area at address: 0x0000 - 0x0100, used by CP/M and
; HW-Monitor
; By Romych 2026-02-03
; =======================================================
IFNDEF _RAM
DEFINE _RAM
MODULE RAM
@warm_boot EQU 0x0000 ; Jump warm_boot (Restart)
@warm_boot_addr EQU 0x0001 ; address of warm boot entry point
@iobyte EQU 0x0003 ; Input/Output mapping
@cur_user_drv EQU 0x0004 ; [7:4] - curent user, [3:0] - current drive
@bdos_enter EQU 0x0005 ; Jump bdos (CALL 5 to make CP/M requests)
@bdos_ent_addr EQU 0x0006 ; addres of BDOS entry point
;@RST1 EQU 0x0008
;@RST1_handler_addr EQU 0x0009
;RST2 EQU 0x0010
;RST3 EQU 0x0018
;RST4 EQU 0x0020
;RST5 EQU 0x0028
;RST6 EQU 0x0030
;RST7 EQU 0x0038
@fcb1 EQU 0x005c ; Default FCB, 16 bytes
@fcb2 EQU 0x006c
;NMI_ISR EQU 0x0066
@dma_buffer EQU 0x0080 ; Default "DMA" 128 bytes buffer
@p_cmd_line_len EQU 0x0080 ; command line character count
@p_cmd_line EQU 0x0081 ; command line buffer
@bios_stack EQU 0x0100
@tpa_start EQU 0x0100 ; start of program
@video_ram EQU 0x4000
ENDMODULE
ENDIF