Skip to content

Commit

Permalink
Add MEGA65 special GW and sample shutdown.com code using it
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Oct 5, 2024
1 parent cbe2e3b commit 1886d27
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 84 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PRG = emu.prg
LD65_CFG = emu.ld
PRG_ON_DISK = emu
MAP_FILE = emu.map
SOURCES = console.asm cpu.asm loader.asm main.asm shell.asm fontdata.asm disk.asm
SOURCES = console.asm cpu.asm loader.asm main.asm shell.asm fontdata.asm disk.asm megagw.asm
INCLUDES = $(shell ls *.inc) cpm/bios.inc cpm/cpm22.inc
OBJECTS = $(SOURCES:.asm=.o)
M65_IP = 192.168.0.65
Expand Down Expand Up @@ -58,10 +58,12 @@ main.o: 8080/*.com 8080/mbasic-real.com
$(PRG): $(OBJECTS) $(LD65_CFG) $(ALL_DEPENDS)
$(LD65) $(LD65_OPTS) -o $@ $(OBJECTS)

cpm.dsk: diskdefs Makefile
cpm.dsk: diskdefs apps/*.com $(ALL_DEPENDS)
$(MAKE) -C apps/
rm -f $@
mkfs.cpm -f mega65 $@
cpmcp -f mega65 $@ dist/cpm-apps/* 0:
cpmcp -f mega65 $@ apps/*.com 0:
cpmls -f mega65 -D $@

runme.bin: runme.asm
Expand All @@ -83,6 +85,7 @@ dist: $(DISK_IMAGE)
clean:
$(RM) -f $(PRG) *.o *.lst $(DISK_IMAGE) $(MAP_FILE) runme.bin cpm.dsk
$(MAKE) -C cpm clean
$(MAKE) -C apps clean

distclean:
$(MAKE) clean
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ via HALT opcodes. For now, original DR's CPM (BDOS and CCP) v2.2 is used.

Have a look in directory `dist/bin` for a D81 disk image file (`mega65.d81`) for MEGA65.

Here is a link for you: https://raw.githubusercontent.com/lgblgblgb/mega80/refs/heads/master/dist/bin/mega65.d81

## Limitations / problems / plans

* Current code base is chaotic since major parts of it was written by me in 2017 and I only
Expand All @@ -32,10 +34,15 @@ Have a look in directory `dist/bin` for a D81 disk image file (`mega65.d81`) for
* Commander X16 **if** CPU is 65816 and it can access RAM in higher bankes freely
* Apple IIgs? Unfortunately I don't know too much about Apple computers, but could be a fun ...
* Porting for non-65xx CPU based platforms: certainly it's not impossible but then you need to rewrite everything,
as it's an assembly project.
as it's an assembly project and heavily based on 65xx assembly (even to port to 65816 would require major modifications)
* Integrated on-the-fly memory monitor and things like that
* No, I don't plan CP/M v3. The problem: it requires extensive bank switching and other difficulties,
* No, I don't plan CP/M v3 (as far as I can see now). The problem: it requires extensive bank switching and other difficulties,
since I'm emulating i8080 (later hopefully a Z80) emulating bank switching would be impossible or very slow
* Native BDOS? Maybe adopoting Hjalfi's CPM65 with added Z80/i8080 CPU emulation to allow execute both ordinary
CP/M (CP/M-80) and CP/M-65 applications.
* Also a native BDOS-replacement can be written which does not use CP/M filesystem internally but normal FAT32,
thus MEGA65's SD-card would be seen from CP/M as-is without major issue to import/export data/programs between
MEGA65 and CP/M environment all the time.

## Building

Expand All @@ -56,13 +63,13 @@ Only tested with version v1.20.3 (as of I am writing this), so any older version
can cause problems, like certain ASSERT features was introduced in v1.18.1 but there
can be other problems as well.

### Standard UNIX stuff, like sed, make ...
### Standard UNIX stuff (like sed, make ...)

Using Linux or other kind of UNIX-class OS (including Mac) should be enough.

### Python 3

### c1541

### cpmtools

### wget

67 changes: 0 additions & 67 deletions README.md.OLD

This file was deleted.

4 changes: 4 additions & 0 deletions apps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*.com2
/*.sym
/*.map
/*.lst
21 changes: 21 additions & 0 deletions apps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ASM80 = sjasmplus --nologo --msg=war --i8080 --fullpath --color=auto

SOURCES = $(shell ls *.asm)
#INCLUDES = $(shell ls *.inc)
INCLUDES =
PROGRAMS = $(SOURCES:.asm=.com)


all: $(PROGRAMS)


%.com: %.asm Makefile $(INCLUDES)
@echo "----[ Assembling CP/M app $< --> $@ ]----"
rm -f $@ $(@)2
$(ASM80) --raw=$(@)2 $<
mv $(@)2 $@

clean:
rm -f *.com *.com2 *.sym *.lst *.map

.PHONY: all clean
23 changes: 23 additions & 0 deletions apps/shutdown.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ORG $100

; BDOS function to display a '$' terminated string
LD C,9
LD DE, msg
CALL 5

; BDOS function to get a character
LD C,1
CALL 5
CP A,'y'
JP Z, shutdown
CP A,'Y'
JP Z, shutdown

JP 0

shutdown:
XOR A ; Set A to zero for MEGA-GW function 0: shutdown, in this case no further parameter is needed
JP $FFFF


msg: DB "Press Y to confirm MEGA/80 CP/M shutdown (FS changes - if any - will be lost) $"
Binary file added apps/shutdown.com
Binary file not shown.
1 change: 1 addition & 0 deletions cpm/bios.asm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ M65BIOS_GO_CPM:
LD (6), HL
LD A, 0x76 ; HALT opcode at $FFFF -> special MEGA65 gw for future stuff
LD (0xFFFF),A
LD (0xFFFE),A ; guarding HALT
JP M65BDOS_CBASE ; Execute CCP (C register is needed to be initialized by the native BIOS before calling us here!)

; ------------------------------------------------------------
Expand Down
22 changes: 12 additions & 10 deletions main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,34 @@ bios_image: .INCBIN "cpm/bios.bin",0,M65BIOS_NONBSS_SIZE
LDA cpu_pch
AND cpu_pcl
CMP #$FF
BEQ @mega65_special
BEQ mega65_special
LDA cpu_pch
CMP #.HIBYTE(M65BIOS_START_BIOS)
BNE @not_halt_tab
BNE not_halt_tab
LDA cpu_pcl
SEC
SBC #M65BIOS_HALT_TAB_LO
CMP #M65BIOS_ALL_CALLS
BCS @bad_halt_ofs
BCS bad_halt_ofs
ASL A
TAX
JMP (@bios_call_table,X)
@not_halt_tab:
JMP (bios_call_table,X)
not_halt_tab:
WRISTR {13,10,"*** Emu trap not on BIOS gw page / unexpected HALT opcode"}
JMP fatal_error
@bad_halt_ofs:
bad_halt_ofs:
PHA
WRISTR {13,10,"*** Invalid BIOS call #$"}
PLA
JSR write_hex_byte
JMP fatal_error
@mega65_special:
WRISTR {13,10,"*** MEGA65 special gw is not ready yet"}
mega65_special:
.IMPORT megagw
JSR megagw
LBCC cpu_start_with_ret
WRISTR {13,10,"*** Invalid MEGA-GW call"}
JMP fatal_error
@bios_call_table:
bios_call_table:
.WORD BIOS_BOOT, BIOS_WBOOT, BIOS_CONST, BIOS_CONIN
.WORD BIOS_CONOUT, BIOS_LIST, BIOS_PUNCH, BIOS_READER
.WORD BIOS_HOME, BIOS_SELDSK, BIOS_SETTRK, BIOS_SETSEC
Expand Down Expand Up @@ -259,7 +262,6 @@ bios_image: .INCBIN "cpm/bios.bin",0,M65BIOS_NONBSS_SIZE
; --------------------------------------------------------

.PROC BIOS_SELDSK
;BRA error
LDA cpu_c
BNE error ; currently one drive is supported (drive zero) only, thus non-zero value is an error
LDA #.LOBYTE(M65BIOS_DPH)
Expand Down
Loading

0 comments on commit 1886d27

Please sign in to comment.