# HG changeset patch # User Shinji KONO # Date 1545721025 -32400 # Node ID f20bf987469706be6ed98b3317b5f7af248a448a # Parent 03a26438ab8daa0858aaa4a954843ac4adfa7ad1 fix os9 dir diff -r 03a26438ab8d -r f20bf9874697 OS9.dsk Binary file OS9.dsk has changed diff -r 03a26438ab8d -r f20bf9874697 WORK.dsk Binary file WORK.dsk has changed diff -r 03a26438ab8d -r f20bf9874697 os9/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/Makefile Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,35 @@ +all: os9mod make9rom os9v2.rom os9v1.rom level1/init level2/init + +CC=clang +CFLAGS = -g + +os9mod : crc.c os9.h os9mod.c os9.h + $(CC) $(CFLAGS) -o os9mod crc.c os9mod.c + +make9rom : makerom.c + $(CC) $(CFLAGS) -o make9rom makerom.c + +clean : + rm -rf makerom *.rom os9mod *.dSYM + +os9v1.rom : make9rom level1/init + ./make9rom -o os9v1.rom level1/shell level1/sysgo level1/ioman level1/term level1/pty level1/pdisk level1/d0 level1/d1 level1/vrbf level1/v0 level1/clock level1/scf level1/rbf level1/init level1/os9p2 level1/os9p1 + +os9v2.rom : make9rom level2/init + ./make9rom -o os9v2.rom -2 level2/Shell level2/dir level2/d1 level2/ioman level2/os9p3_perr level2/os9p4_regdump level2/pipe level2/piper level2/pipeman level2/v0 level2/vrbf level2/scf level2/rbf level2/os9p2 level2/sysgo level2/clock level2/pdisk level2/d0 level2/pty level2/term level2/init level2/boot level2/os9p1 + +level1/init : nitros9-code + cd level1 ; make + +level2/init : nitros9-code + cd level2 ; make + +nitros9-code : + hg clone http://hg.code.sf.net/p/nitros9/code nitros9-code + +runv2 : + ../src/v09c -rom os9v2.rom -0 OS9.dsk -1 WORK.dsk + +runv1 : + ../src/v09 -rom os9v1.rom -0 OS9.dsk -1 WORK.dsk + diff -r 03a26438ab8d -r f20bf9874697 os9/OS9.dsk Binary file os9/OS9.dsk has changed diff -r 03a26438ab8d -r f20bf9874697 os9/WORK.dsk Binary file os9/WORK.dsk has changed diff -r 03a26438ab8d -r f20bf9874697 os9/crc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/crc.c Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,49 @@ +#include + +#include "os9.h" + +int os9_crc(OS9_MODULE_t *mod) +{ + int i; + u_char crc[3] = {0xff, 0xff, 0xff}; + u_char *ptr = (u_char *) mod; + u_char a; + + for (i = 0; i < INT(mod->size); i++) + { + a = *(ptr++); + + a ^= crc[0]; + crc[0] = crc[1]; + crc[1] = crc[2]; + crc[1] ^= (a >> 7); + crc[2] = (a << 1); + crc[1] ^= (a >> 2); + crc[2] ^= (a << 6); + a ^= (a << 1); + a ^= (a << 2); + a ^= (a << 4); + if (a & 0x80) { + crc[0] ^= 0x80; + crc[2] ^= 0x21; + } + } + if ((crc[0] == OS9_CRC0) && + (crc[1] == OS9_CRC1) && + (crc[2] == OS9_CRC2)) + return 1; + + return 0; +} + +int os9_header(OS9_MODULE_t *mod) +{ + u_char tmp = 0x00; + u_char *ptr = (u_char *) mod; + int i; + + for (i = 0; i < OS9_HEADER_SIZE; i++) + tmp ^= *(ptr++); + + return tmp; +} diff -r 03a26438ab8d -r f20bf9874697 os9/level1/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/level1/Makefile Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,89 @@ + +OS9SRC = ../nitros9-code +SRCDIR = $(OS9SRC)/level1/modules +SRCCMD = $(OS9SRC)/level1/cmds +SRCDIR2 = $(OS9SRC)/level2/modules + +A09 = ../../src/a09 -I $(OS9SRC)/defs/ + +MOD = pdisk init os9p1 os9p2 ioman pipe piper rbf scf term pty d0 d1 vrbf v0 clock shell dir mdir sysgo shell + +all : ${MOD} + cd cmds; make + +clean : + cd cmds; make clean + rm -f $(MOD) *.lst krn.asm + +LST = -l $@.lst + +# our own module for sbc09 +# CoCoOS9's level1/os9p1.asm has wrong vector value, use our own + +pdisk : + $(A09) pdisk.asm -o pdisk $(LST) + +#boot : boot.asm +# $(A09) boot.asm -o boot $(LST) + +init : init.asm + $(A09) ${SRCDIR}/init.asm -o $@ $(LST) +# $(A09) init.asm -o init $(LST) + +pty : pty.asm + $(A09) pty.asm -o pty $(LST) + +term : pty-dd.asm + $(A09) pty-dd.asm -o term $(LST) + +d0 : d0.asm + $(A09) d0.asm -o d0 $(LST) + +d1 : d1.asm + $(A09) d1.asm -o d1 $(LST) + +clock : clock.asm + $(A09) clock.asm -o clock $(LST) + +vrbf : + $(A09) ../level2/vrbf.asm -o $@ $(LST) + +v0 : + $(A09) v0.asm -o $@ $(LST) + +# os9 level1 moduels + +shell : $(SRCCMD)/shell_21.asm + $(A09) $< -o $@ $(LST) + +mdir : ${SRCCMD}/mdir.asm + $(A09) $< -o $@ $(LST) + +dir : ${SRCCMD}/dir.asm + $(A09) ${SRCCMD}/dir.asm -o dir $(LST) + +os9p1 : + cat ${OS9SRC}//defs/coco.d ${SRCDIR}/kernel/krn.asm > krn.asm + $(A09) -I ../nitros9-code/level1/modules/kernel/ krn.asm -o os9p1 $(LST) + +os9p2 : + $(A09) ${SRCDIR}/kernel/krnp2.asm -o os9p2 $(LST) + +sysgo : + $(A09) sysgo.asm -o sysgo $(LST) + +ioman : + $(A09) ${SRCDIR}/ioman.asm -o ioman $(LST) + +pipe : + $(A09) ${SRCDIR}/pipe.asm -o pipe $(LST) + +piper : + $(A09) ${SRCDIR}/piper.asm -o piper $(LST) + +rbf : + $(A09) ${SRCDIR}/rbf.asm -o rbf $(LST) + +scf : + $(A09) ${SRCDIR}/scf.asm -o scf $(LST) + diff -r 03a26438ab8d -r f20bf9874697 os9/level1/clock.asm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/level1/clock.asm Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,108 @@ +******************************************************************** +* Clock - OS-9 Level One V2 Clock module +* +* $Id: clock.asm,v 1.1.1.1 2001/02/21 23:30:52 boisy Exp $ +* +* NOTE: This clock is TOTALLY VALID for ALL DATES between 1900-2155 +* +* Ed. Comments Who YY/MM/DD +* ------------------------------------------------------------------ +* 5 Tandy/Microware original version +* 6 Modified to handle leap years properly for BGP 99/05/03 +* 1900 and 2100 A.D. + + nam Clock + ttl OS-9 Level One V2 Clock module + + ifp1 + use defsfile + endc + +tylg set Systm+Objct +atrv set ReEnt+rev +rev set $01 +edition set $06 +TimerPort set $e030 +TkPerSec set 60 +TkPerTS equ TkPerSec/10 ticks per time slice + + + mod eom,name,tylg,atrv,ClkEnt,size + +size equ . + +name fcs /Clock/ + fcb edition + +SysTbl fcb F$Time + fdb FTime-*-2 + fcb $80 + + +ClockIRQ ldx #TimerPort + lda ,x + bita #$10 + bne L00B4 +L00AE jsr [>D.Poll] poll ISRs + bcc L00AE keep polling until carry set + jmp [>D.AltIRQ] jump into an alternate IRQ if available + +L00B4 + ldb #$8f start timer + stb ,x + + dec D.Clock] + +ClkEnt equ * + ldd #59*256+$01 last second and last tick + std PIA0Base+3 +* nop +* nop +* sta >$FFDF turn off ROM mode +* jmp >Bt.Start+2 jump to boot +* BasicRL equ *-BasicRst + ENDC + ENDC + +Init fcs /Init/ + +* Entry: X = pointer to start of nul terminated string +* Exit: D = length of string +strlen pshs x + ldd #-1 +go@ addd #$0001 + tst ,x+ + bne go@ + puls x,pc + +* Display carriage-return/line-feed. +WriteCR pshs y + leax CrRtn,pcr + ldy #$0001 + os9 I$WritLn + puls y,pc + +********************************************************** +* SysGo Entry Point +********************************************************** +start leax >IcptRtn,pcr + os9 F$Icpt +* Set priority of this process + os9 F$ID + ldb #DefPrior + os9 F$SPrior + +* Write OS name and Machine name strings + leax Init,pcr + clra + pshs u + os9 F$Link + bcs SignOn + stx Banner,pcr + ldy #BannLen + lda #$01 standard output + os9 I$Write write out banner + +* Set default time and start Clock module + leax >DefTime,pcr + os9 F$STime set time to default + + IFEQ 1 + leax >MDIR,pcr + leau >mdirprm,pcr + ldd #$0100 + ldy #$0003 + os9 F$Fork + bcs mdirend AutoEx failed.. + os9 F$Wait + ldu ,s + bra mdirend +MDIR fcc "mdir" + fcb $0d +mdirprm fcc "-e" + fcb C$CR +mdirend + ldu ,s + ENDC + +* IFEQ ROM +* Change EXEC and DATA dirs + leax >ExecDir,pcr + lda #EXEC. + os9 I$ChgDir change exec. dir + leax >DefDev,pcr +* Made READ. so that no write occurs at boot (Boisy on Feb 5, 2012) + lda #READ. + os9 I$ChgDir change data dir. + bcs L0125 +* leax >HDDev,pcr +* lda #EXEC. +* os9 I$ChgDir change exec. dir to HD +* ENDC + +L0125 equ * + IFEQ atari+corsham + IFEQ Level-1 +* Setup BASIC code (CoCo port only) +* leax >BasicRst,pcr +* ldu #D.CBStrt +* ldb #BasicRL +*CopyLoop lda ,x+ +* sta ,u+ +* decb +* bne CopyLoop + ELSE + os9 F$ID get process ID + lbcs L01A9 fail + leax ,u + os9 F$GPrDsc get process descriptor copy + lbcs L01A9 fail + leay ,u + ldx #$0000 + ldb #$01 + os9 F$MapBlk + bcs L01A9 + +* lda #$55 set flag for Color BASIC +* sta Shell,pcr +* leau >Startup,pcr +* ldd #256 +* ldy #StartupL +* os9 F$Fork +* bcs DoAuto Startup failed.. +* os9 F$Wait +* ENDC + +* Fork AutoEx here +*DoAuto leax >AutoEx,pcr +* leau >CRtn,pcr +* ldd #$0100 +* ldy #$0001 +* os9 F$Fork +* bcs L0186 AutoEx failed.. +* os9 F$Wait + +L0186 equ * + ldu ,s +FrkShell leax >ShellPrm,pcr + leay ,u + ldb #ShellPL +L0190 lda ,x+ + sta ,y+ + decb + bne L0190 +* Fork final shell here + leax >Shell,pcr + lda #$01 D = 256 (B already 0 from above) + ldy #ShellPL + IFGT Level-1 + os9 F$Chain Level 2/3. Should not return.. + ldb #$06 it did! Fatal. Load error code + bra Crash + +L01A9 ldb #$04 error code +Crash clr >DPort+$08 turn off disk motor + jmp TimerPort + jmp [>D.Clock] + +TkPerTS equ 2 + +ClkEnt equ * + pshs cc + orcc #FIRQMask+IRQMask mask ints + leax >ClockIRQ,pcr + stx ClockFIRQ,pcr + stx $FFF6 must be a RAM + endc +* install system calls + leay >SysTbl,pcr + os9 F$SSvc + ldd #59*256+TkPerTS last second and time slice in minute + std basic.asm + +basic.s : basic.asm + $(A09) -l $@.lst -s $@ basic.asm + +mdir : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +mfree : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +proc : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +procs : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +reboot : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +smap : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +mmap : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +pmap : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm +dmem : + $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm + +asm : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +attr : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +calldbg : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +cmp : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +config : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +copy : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +cputype : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +date : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +debug : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +del : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +deldir : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +devs : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +dir : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +dir_cb : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +dirsort : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +disasm : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +dump : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +dw.as : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +echo : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +edit : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +error : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +free : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +help : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +ident : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +irqs : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +link : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +list : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +load : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +login : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +makdir : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +pxd : + $(A09) -D PXD -l $@.lst -o $@ $(SRC1)/pd.asm +pwd : + $(A09) -D PWD -l $@.lst -o $@ $(SRC1)/pd.asm +prompt : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +shellplus : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +sleep : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +tee : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +touch : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +tsmon : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm +unlink : + $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm diff -r 03a26438ab8d -r f20bf9874697 os9/level2/cmds/defsfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/level2/cmds/defsfile Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,3 @@ +* Main defsfile for OS-9 Level One V1 +* + use ../defsfile diff -r 03a26438ab8d -r f20bf9874697 os9/level2/cmds/fixbasic.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/level2/cmds/fixbasic.pl Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,49 @@ +#!/usr/bin/perl +# + +while(<>) { + next if (/^ACIA/ .. /^TDRE/) ; + next if (/^TSTBRK/ .. /^ END/) ; + if (/^CLEAR/) { +print <<"EOFEOF" + JSR \$24 ;; echo off (but it is not suuported on pty.asm ) +EOFEOF + } + if (/^GL02/) { + print "GL02\n"; # do not echo input + next; + } + print; +} + + +print <<"EOFEOF" +****************************** +****************************** +TSTBRK bsr BRKEEE + bcc GETC05 +GETCHR bsr INEEE + CMPA \#ETX ; 3 + BNE GETC05 + JMP BREAK +INTEEE +GETC05 RTS +PUTCHR INC ZONE + JMP OUTEEE +****************************** +****************************** +INEEE PSHS D + JSR 0 + STB ,S + PULS D,PC +OUTEEE PSHS D + TFR A,B + JSR 3 + PULS D,PC +BRKEEE PSHS D + JSR \$F + PULS D,PC +****************************** +****************************** + END +EOFEOF diff -r 03a26438ab8d -r f20bf9874697 os9/level2/cmds/loop.asm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/level2/cmds/loop.asm Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,45 @@ +******************************************************************** +* loop dummy loader +* +* $Id$ +* +* Edt/Rev YYYY/MM/DD Modified by +* Comment +* ------------------------------------------------------------------ +* 1 2018/07/30 S. Kono + + nam Loop + ttl Dummy loop + + ifp1 + use defsfile + endc + +* Module header definitions +tylg set Prgrm+Objct +atrv set ReEnt+rev +rev set $00 +edition set 1 + + mod eom,name,tylg,atrv,start,size + + org 0 +count rmb 2 +size equ . + +name fcs /Loop/ + fcb edition + +start ldy #4000 +l1 ldx #0 +l0 leax -1,x + bne l0 + leay -1,y + bne l1 +Exit clrb + os9 F$Exit + + + emod +eom equ * + end diff -r 03a26438ab8d -r f20bf9874697 os9/level2/cmds/sbc09.asm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/level2/cmds/sbc09.asm Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,264 @@ +******************************************************************** +* sbc09 emulator +* +* $Id$ +* +* Edt/Rev YYYY/MM/DD Modified by +* Comment +* ------------------------------------------------------------------ +* 1 2018/08/20 S. Kono +* Emulatoe sbc09 on os9 lv2 + + nam Sbc09 + ttl Sbc09 emulator + + ifp1 + use defsfile + endc + +* Module header definitions +tylg set Prgrm+Objct +atrv set ReEnt+rev +rev set $00 +edition set 1 + + mod eom,name,tylg,atrv,start,size + + org 0 +ioentry rmb $80 +filepath rmb 2 +parmptr rmb 2 +stdin rmb 1 +chksum rmb 1 +bcount rmb 1 +adr rmb 2 +work rmb 2 +readbuff rmb $100 + org $400 +emstart rmb $e000-. +size equ . + +name fcs /Sbc09/ + fcb edition + +start + clr PIA0Base+3 +* nop +* nop +* sta >$FFDF turn off ROM mode +* jmp >Bt.Start+2 jump to boot +* BasicRL equ *-BasicRst + ENDC + ENDC + +Init fcs /Init/ + +* Entry: X = pointer to start of nul terminated string +* Exit: D = length of string +strlen pshs x + ldd #-1 +go@ addd #$0001 + tst ,x+ + bne go@ + puls x,pc + +* Display carriage-return/line-feed. +WriteCR pshs y + leax CrRtn,pcr + ldy #$0001 + os9 I$WritLn + puls y,pc + +********************************************************** +* SysGo Entry Point +********************************************************** +start leax >IcptRtn,pcr + os9 F$Icpt +* Set priority of this process + os9 F$ID + ldb #DefPrior + os9 F$SPrior + +* Write OS name and Machine name strings + leax Init,pcr + clra + pshs u + os9 F$Link + bcs SignOn + stx Banner,pcr + ldy #BannLen + lda #$01 standard output + os9 I$Write write out banner + +* Set default time + leax >DefTime,pcr + os9 F$STime set time to default + + IFEQ ROM +* Change EXEC and DATA dirs + leax >ExecDir,pcr + lda #EXEC. + os9 I$ChgDir change exec. dir + leax >DefDev,pcr +* Made READ. so that no write occurs at boot (Boisy on Feb 5, 2012) + lda #READ. + os9 I$ChgDir change data dir. + bcs L0125 +* leax >HDDev,pcr +* lda #EXEC. +* os9 I$ChgDir change exec. dir to HD + ENDC + +L0125 equ * + pshs u,y + IFEQ atari+corsham + IFEQ Level-1 +* Setup BASIC code (CoCo port only) +* leax >BasicRst,pcr +* ldu #D.CBStrt +* ldb #BasicRL +*CopyLoop lda ,x+ +* sta ,u+ +* decb +* bne CopyLoop + ELSE + os9 F$ID get process ID + lbcs L01A9 fail + leax ,u + os9 F$GPrDsc get process descriptor copy + lbcs L01A9 fail + leay ,u + ldx #$0000 + ldb #$01 + os9 F$MapBlk + bcs L01A9 + +* lda #$55 set flag for Color BASIC +* sta Shell,pcr +* leau >Startup,pcr +* ldd #256 +* ldy #StartupL +* os9 F$Fork +* bcs DoAuto Startup failed.. +* os9 F$Wait +* ENDC + +* Fork AutoEx here +*DoAuto leax >AutoEx,pcr +* leau >CRtn,pcr +* ldd #$0100 +* ldy #$0001 +* os9 F$Fork +* bcs L0186 AutoEx failed.. +* os9 F$Wait + + IFEQ Level-1 + leax >MDIR,pcr + leau >mdirprm,pcr + ldd #$0100 + ldy #$0003 + os9 F$Fork + bcs L0186 AutoEx failed.. + os9 F$Wait + bra L0186 +MDIR fcs "mdir" + fcb $0d + ENDC +L0186 equ * + puls u,y +FrkShell leax >ShellPrm,pcr + leay ,u + ldb #ShellPL +L0190 lda ,x+ + sta ,y+ + decb + bne L0190 +* Fork final shell here + leax >Shell,pcr + lda #$01 D = 256 (B already 0 from above) + ldy #ShellPL + IFGT Level-1 + os9 F$Chain Level 2/3. Should not return.. + ldb #$06 it did! Fatal. Load error code + bra Crash + +L01A9 ldb #$04 error code +Crash clr >DPort+$08 turn off disk motor + jmp +#include +#include +#include + +// #define DEBUG 1 + +/* + * Level1 + * os9p1 should be 0xf800 + * it searches ram from the beginning + * rom modules are searched from just after the end of RAM + * + * Level2 + * Coco 512kb memory space + * last 8k is a ROM (can be switched?) ( block 0x3f ) + * os9p1 search module on 0x0d00~0x1e00 at block 0x3f + * + * 8k block ( offset 0xc000 ) + * + * 0xe000 - 0xccff 0xff + * 0xed00 - 0xfeff os9 modules, os9p1 should be the last + * MMU doesnot touch below + * 0xff80 - 0xffdf IO port ( ACIA, clock, pdisk, MMU ) + * 0xffd0 - 0xffef boot code + * 0xfff0 - 0xffff intr vector + * ... next few blocks as extended ROM + * lv2 6809 memory check routine destroys 0x200 on page 0x40 + * sta >-$6000,x + * avoid 0x200 + * + */ + +int level = 1; +int IOBASE = 0xe000; +int IOSIZE = 0x100; +char * outfile ; + +#define LV2START 0xffd0 // our own small boot for mmu +#define LV2ROMEND 0xff80 + +// #define DEBUG + +typedef struct os9module { + int size; + int entry; + int location; + int ioflag; + unsigned char *mod; + char *name; + struct os9module *next; +} *MPTR ; + +unsigned short vec[8]; + +struct os9module * +readOS9module(char *filename) +{ + FILE *fp = fopen(filename,"rb"); + if (fp==0) { + fprintf(stderr,"cannot read %s\n",filename); + exit(1); + } + struct stat st; + fstat(fileno(fp),&st); + int size = st.st_size; + struct os9module *m = malloc(size + sizeof(struct os9module)); + m->size = size; + m->next = 0; + m->ioflag = 0; + m->mod = (unsigned char*)m + sizeof(struct os9module); + fread(m->mod , size, 1, fp); + m->name = (char*) (m->mod + (m->mod[4]*256 + m->mod[5]) ); + m->entry = m->mod[9]*256 + m->mod[10] ; + fclose(fp); + return m; +} + +void +fputword(unsigned short x, FILE *fp) +{ + fputc((x>>8)&0xff,fp); + fputc(x&0xff,fp); +} + +void printOs9Str(char *p) +{ + char *q = p; + while((*p & 0x80)==0) { + putchar(*p); + p++; + } + putchar(*p & 0x7f); + while(p>8; + adr[1] = vec&0xff; + adr += 2; + } +} + +int search_vector(MPTR m) { + unsigned char v[] = { 0x6E, 0x9F, 0x00, 0x2C, 0x6E}; + for( unsigned char *p = m->mod ; p < m->mod + m->size; p++ ) { + int i=0; + for(; i< sizeof(v); i++) { + if (p[i]!=v[i]) break; + } + if (i==sizeof(v)) + return p - m->mod; + } + return 0; +} + +// calcurate position from the botton +// avoid v09 IO map on 0xe000-0xe800 +// os9p1 have to be last and at 0xf800 +int findLocation(MPTR m, int loc) { + if (m==0) return loc; + int top = findLocation(m->next, loc) - m->size; + if (m->next==0) { + if (level == 1) + if (m->size > 0xff80-0xf800 ) { + top = 0x10000-(m->size+0x80); + } else { + top = 0xf800; // OS9p1 + } + else { +#if 0 + // old level2 kernel has vector at the bottom + top = 0x10000-(m->size+0x80); + rewrite_vector(m,m->size,m->mod+getword(m->mod+2),7); +#else + top = 0xf000; // level2 OS9p1 starts here + // and theses area are RAM /REGISTER STACK/ +#endif + } + } + if (level==1 && !(( top+m->size < IOBASE ) || ( IOBASE+IOSIZE < top)) ) { + top = IOBASE-m->size-1; + m->ioflag = 1; +#ifdef DEBUG + printf("*"); +#endif + } else if (level==2 && 0xed00 > top) { + m->ioflag = 1; + } + m->location = top; +#ifdef DEBUG + printf("mod "); + printOs9Str(m->name); + printf(" \t: 0x%x - 0x%x\n",top, top + m->size); +#endif + return top; +} + +int +main(int ac, char *av[]) +{ + int vectable = 0; + struct os9module *m = 0, root ; + root.size = 0; + root.mod = 0; + m = &root; + + for(int i = 1 ; inext = cur; + m = cur; + } + + FILE *romfile; + unsigned pos; + if (outfile==0) return 1; + + romfile=fopen(outfile,"wb"); + if(!romfile) { + fprintf(stderr,"Cannot create file %s\n",av[1]); + exit(1); + } + + + int start = findLocation(root.next,0); + start = start&0xf800; + printf("\n\n"); + + if (level==2) { + for(int i=0; i<0xd00; i++) fputc(0xff,romfile); + pos = 0xed00; + } else { + pos = start; + } + int ofs = 0; + struct os9module *os9p1 = 0; + for(struct os9module *cur = root.next; cur ; cur = cur->next ) { + if ( level==2 && cur->ioflag ==1) continue; + // last module have to os9p1 + if ( cur->next == 0 ) { + os9p1 = cur; + if ( level==1 ) { + if (os9p1->size > 0x07f0) { + ofs = (os9p1->size+0xf)&0xfff0; + ofs -= 0x07f0; + } + for(; pos < 0xf800-ofs ; pos++) { // os9p1 begins at 0xf800 + fputc(0xff,romfile); + } + } else { +#if 0 + int pend = 0x10000-( cur->size +0x80); + for(; pos < pend ; pos++) { // os9p1 ends 0xff7f + fputc(0xff,romfile); + } +#endif + for(; pos < 0xf000 ; pos++) { // level2 os9p1 start from 0xf000 + fputc(0xff,romfile); + } + } + } + printf("mod "); + printOs9Str(cur->name); + cur->location = pos; + fwrite(cur->mod, cur->size, 1, romfile); + printf(" \t: 0x%x - 0x%x size 0x%04x entry 0x%x\n",pos, pos + cur->size-1,cur->size,cur->entry+cur->location); +#ifdef DEBUG + printf(" \t: 0x%x \n",cur->location); + printf(" \t: 0x%x - 0x%x : 0x%lx \n",pos, pos + cur->size, ftell(romfile)+start); +#endif + pos = pos+cur->size; + if (level==1 && cur->ioflag) { + if (level==1) { + for(; pos < IOBASE + IOSIZE; pos++) { + fputc(0xff,romfile); + } + printf("*"); + } + } + } + printf("os9 end %x\n",pos); + if (level==1) { + vectable = 0x10000 - 2*7; + for( ; poslocation +vecofs+perm[i]*4,romfile); + } + int entry_ofs = (m->mod[9]<<8) + m->mod[10]; + fputword( os9p1->location + entry_ofs ,romfile); + // printf("os9p1 location ofs %0x\n", os9p1->location); + // printf("vector ofs %0x\n", vecofs); + // printf("reset ofs %0x\n", entry_ofs); + } else { + fputword(0xF82d-ofs,romfile); + fputword(0xF831-ofs,romfile); + fputword(0xF835-ofs,romfile); + fputword(0xF839-ofs,romfile); + fputword(0xF83d-ofs,romfile); + fputword(0xF841-ofs,romfile); + fputword(0xF876-ofs,romfile); + } + } else { + char vector[] = "level2/vector"; + FILE *fp = fopen(vector,"rb"); + if (fp==0) { + fprintf(stderr,"cannot read %s\n",vector); + exit(1); + } + for( ; poslocation); +#endif + printf("os9entry %x\n",os9p1->location+getword(os9p1->mod+9)); + + fputword(os9p1->location+getword(os9p1->mod+9),romfile); // os9p1 entry point + unsigned short vec = os9p1->location+os9p1->size - 18; + fputword(vec,romfile); + fputword(vec+3,romfile); + fputword(vec+6,romfile); + + fputword(vec+9,romfile); + fputword(vec+12,romfile); + fputword(vec+15,romfile); + fputword(LV2START,romfile); + + pos = 0x10000; + int bootsize = 2; + for(struct os9module *cur = root.next; cur ; cur = cur->next ) { + if ( cur->ioflag ==0) continue; + bootsize += cur->size; + } + bootsize += 0x300-2; // to avoid 0x200 bombing + fputc(bootsize>>8,romfile); + fputc(bootsize&0xff,romfile); + pos += 2; + for( int i = 0; i<0x300-2; i++) fputc(0xff,romfile); + for(struct os9module *cur = root.next; cur ; cur = cur->next ) { + if ( cur->ioflag ==0) continue; + cur->location = pos; + printf("mod "); + printOs9Str(cur->name); + fwrite(cur->mod, cur->size, 1, romfile); + printf(" \t: 0x%x - 0x%x size 0x%04x entry 0x%x\n",pos, pos + cur->size-1, cur->size, cur->entry+cur->location); +#ifdef DEBUG + printf(" \t: 0x%x \n",cur->location); + printf(" \t: 0x%x - 0x%x : 0x%lx \n",pos, pos + cur->size, ftell(romfile)+start); +#endif + pos += cur->size; + } + while(pos++ & 0xff) fputc(0xff,romfile); + } + if (level==1) + printf("boot rom from 0x%lx\n",0x10000-ftell(romfile)); + else { + long size; + printf("boot rom from 0xc000 size 0x%lx\n",(size=ftell(romfile))); + if (size > 0x4d00 + 0x2000) { + printf(" was too big. make it less than 0x6d00\n"); + } + } + fclose(romfile); + return 0; +} + + diff -r 03a26438ab8d -r f20bf9874697 os9/os9.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/os9.h Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,94 @@ +typedef unsigned char u_char; + +typedef struct os9_module_t { + u_char id[2]; + u_char size[2]; + u_char name[2]; + u_char tyla; + u_char atrv; + u_char parity; + union { + u_char data[1]; /* plain modules */ + struct { + u_char exec[2]; + u_char data[1]; + } system; + struct { + u_char exec[2]; + u_char mem[2]; + u_char data[1]; + } program; + struct { + u_char exec[2]; + u_char mem[2]; + u_char mode[1]; + u_char data[1]; + } driver; + struct { + u_char exec[2]; + u_char data[1]; + } file_mgr; + struct { + u_char fmgr[2]; + u_char driver[2]; + u_char mode; + u_char port[3]; + u_char opt; + u_char dtype; + u_char data[1]; + } descriptor; + } data; +} OS9_MODULE_t; + +#define OS9_HEADER_SIZE 9 + +#define TYPE_MASK 0xF0 +typedef enum os9_type_t { + NULL_TYPE = 0, + Prgrm, + Sbtrn, + Multi, + Data, + SSbtrn, + TYPE_6, + TYPE_7, + TYPE_8, + TYPE_9, + TYPE_A, + TYPE_B, + Systm, + FlMgr, + Drivr, + Devic +} OS9_TYPE_t; + +#define LANG_MASK 0x0F +typedef enum os9_lang_t { + NULL_LANG = 0, + Objct, + ICode, + PCode, + CCode, + CblCode, + FrtnCode, + Obj6309, +} OS9_LANG_t; + +#define ATTR_MASK 0xF0 +typedef enum os9_attr_t { + ReEnt = 0x80, + Modprot = 0x40, +} OS9_attr_t; + +#define REVS_MASK 0x0F + +#define OS9_ID0 0x87 +#define OS9_ID1 0xcd + +#define OS9_CRC0 0x80 +#define OS9_CRC1 0x0F +#define OS9_CRC2 0xE3 + +#define INT(foo) (foo[0] * 256 + foo[1]) +int os9_crc(OS9_MODULE_t *mod); +int os9_header(OS9_MODULE_t *mod); diff -r 03a26438ab8d -r f20bf9874697 os9/os9mod.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os9/os9mod.c Tue Dec 25 15:57:05 2018 +0900 @@ -0,0 +1,187 @@ +#include +#include +#include +#include +#include "os9.h" + + +u_char *os9_string(u_char *string); +void ident(OS9_MODULE_t *mod); +void usage(void); +long pos; + +static char *types[16] = { + "???", "Prog", "Subr", "Multi", "Data", "USR 5", "USR 6", "USR 7", + "USR 8", "USR 9", "USR A", "USR B", "System", "File Manager", + "Device Driver", "Device Descriptor" +}; + +static char *langs[16] = { + "Data", "6809 Obj", "Basic09 I-Code", "Pascal P-Code", "C I-Code", + "Cobol I-Code", "Fortran I-Code", "6309 Obj", "???", "???", "???", + "???", "???", "???", "???", "???" +}; + +int offset = 0; + +int main(int argc, char **argv) +{ + char *filename = NULL; + FILE *fp; + u_char buffer[65536]; /* OS9 Module can't be larger than this */ + OS9_MODULE_t *mod = (OS9_MODULE_t *) buffer; + int i=0, j; + int flag = 0; + + argv++; /* skip my name */ + + if (argc == 1) + usage(); + + while ((argc >= 2) && (*argv[0] == '-')) { + if (*(argv[0] + 1) == 's') { + argc--; + flag = 1; + } else if (*(argv[0] + 1) == 'o') { + argc--; argc--; + argv++; + offset = strtol(argv[0],(char**)0,0); + } else + usage(); + argv++; + } + + + while (argc-- > 1) { + if (*argv==0) return 0; + filename = *(argv++); + + if ((fp = fopen(filename,"rb")) == NULL) { + fprintf(stderr, "Error opening file %s: %s\n", + filename, strerror(errno)); + return 1; + } + + while (!feof(fp)) { + + if (flag) { + int c; + while( !feof(fp) && (c = fgetc(fp)) != 0x87 ); + ungetc(c, fp); + } + + pos = ftell(fp); + if (fread(buffer, OS9_HEADER_SIZE, 1, fp) != 1) { + if (feof(fp)) + break; + else { + fprintf(stderr, "Error reading file %s: %s\n", + filename, strerror(errno)); + return 1; + } + } + + if ((mod->id[0] != OS9_ID0) && (mod->id[1] != OS9_ID1)) { + fprintf(stderr,"Not OS9 module, skipping.\n"); + return 1; + } + + if ((i = os9_header(mod))!=0xff) { + fprintf(stderr, "Bad header parity. Expected 0xFF, got 0x%02X\n", i); + return 1; + } + + i = INT(mod->size) - OS9_HEADER_SIZE; + if ((j = fread(buffer + OS9_HEADER_SIZE, 1, i, fp)) != i) { + fprintf(stderr,"Module short. Expected 0x%04X, got 0x%04X\n", + i + OS9_HEADER_SIZE, j + OS9_HEADER_SIZE); + return 1; + } + ident(mod); + } + fclose(fp); + } + return 0; + +} + +void ident(OS9_MODULE_t *mod) +{ + int i, j; + u_char *name, *ptr, tmp, *buffer = (u_char *) mod; + + i = INT(mod->name); + j = INT(mod->size); + name = os9_string(&buffer[i]); + printf("Offset : 0x%04lx\n", pos + offset); + printf("Header for : %s\n", name); + printf("Module size: $%X #%d\n", j, j); + ptr = &buffer[j - 3]; + printf("Module CRC : $%02X%02X%02X (%s)\n", ptr[0], ptr[1], ptr[2], + os9_crc(mod) ? "Good" : "Bad" ); + printf("Hdr parity : $%02X\n", mod->parity); + + switch ((mod->tyla & TYPE_MASK) >> 4) + { + + case Drivr: + case Prgrm: + i = INT(mod->data.program.exec); + printf("Exec. off : $%04X #%d\n", i, i); + i = INT(mod->data.program.mem); + printf("Data size : $%04X #%d\n", i, i); + break; + + case Devic: + printf("File Mgr : %s\n", + os9_string(&buffer[INT(mod->data.descriptor.fmgr)])); + printf("Driver : %s\n", + os9_string(&buffer[INT(mod->data.descriptor.driver)])); + break; + + case NULL_TYPE: + case TYPE_6: + case TYPE_7: + case TYPE_8: + case TYPE_9: + case TYPE_A: + case TYPE_B: + case Systm: + break; + } + + + + + tmp = buffer[i + strlen((const char *)name)]; + printf("Edition : $%02X #%d\n", tmp, tmp); + printf("Ty/La At/Rv: $%02X $%02x\n", mod->tyla, mod->atrv); + printf("%s mod, ", types[(mod->tyla & TYPE_MASK) >> 4]); + printf("%s, ", langs[mod->tyla & LANG_MASK]); + printf("%s, %s\n", (mod->atrv & ReEnt) ? "re-ent" : "non-share", + (mod->atrv & Modprot) ? "R/W" : "R/O" ); + printf("\n"); +} + +u_char *os9_string(u_char *string) +{ + static u_char cleaned[80]; /* strings shouldn't be longer than this */ + u_char *ptr = cleaned; + int i = 0; + + while (((*(ptr++) = *(string++)) < 0x7f) && + (i++ < sizeof(cleaned) - 1)) + ; + + *(ptr - 1) &= 0x7f; + *ptr = '\0'; + return cleaned; +} +void usage(void) +{ + printf("Usage: os9mod [-s] [-o offset] file [ file ... ]\n"); + printf("Performs an OS-9: 6809 'ident' on the specified files.\n"); + printf(" -s : skip to valid module\n"); + printf(" -o : offset \n\n"); + exit(0); +} diff -r 03a26438ab8d -r f20bf9874697 src/os9/Makefile --- a/src/os9/Makefile Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -all: os9mod makerom os9d.rom os9lv2.rom os9v.rom - -CC=clang -CFLAGS = -g - -os9mod : crc.c os9.h os9mod.c os9.h - $(CC) $(CFLAGS) -o os9mod crc.c os9mod.c - -makerom : makerom.c - $(CC) $(CFLAGS) -o makerom makerom.c - -clean : - rm -rf makerom *.rom os9mod *.dSYM - -os9v1.rom : makerom level1/init - ./makerom -o os9v1.rom level1/shell level1/sysgo level1/ioman level1/term level1/pty level1/pdisk level1/d0 level1/d1 level1/vrbf level1/v0 level1/clock level1/scf level1/rbf level1/init level1/os9p2 level1/os9p1 - -os9v2.rom : makerom level2/init - ./makerom -o os9v2.rom -2 level2/Shell level2/dir level2/d1 level2/ioman level2/os9p3_perr level2/os9p4_regdump level2/pipe level2/piper level2/pipeman level2/v0 level2/vrbf level2/scf level2/rbf level2/os9p2 level2/sysgo level2/clock level2/pdisk level2/d0 level2/pty level2/term level2/init level2/boot level2/os9p1 - -level1/init : nitros9-code - cd level1 ; make - -level2/init : nitros9-code - cd level2 ; make - -nitros9-code : - hg clone http://hg.code.sf.net/p/nitros9/code nitros9-code - diff -r 03a26438ab8d -r f20bf9874697 src/os9/crc.c --- a/src/os9/crc.c Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#include - -#include "os9.h" - -int os9_crc(OS9_MODULE_t *mod) -{ - int i; - u_char crc[3] = {0xff, 0xff, 0xff}; - u_char *ptr = (u_char *) mod; - u_char a; - - for (i = 0; i < INT(mod->size); i++) - { - a = *(ptr++); - - a ^= crc[0]; - crc[0] = crc[1]; - crc[1] = crc[2]; - crc[1] ^= (a >> 7); - crc[2] = (a << 1); - crc[1] ^= (a >> 2); - crc[2] ^= (a << 6); - a ^= (a << 1); - a ^= (a << 2); - a ^= (a << 4); - if (a & 0x80) { - crc[0] ^= 0x80; - crc[2] ^= 0x21; - } - } - if ((crc[0] == OS9_CRC0) && - (crc[1] == OS9_CRC1) && - (crc[2] == OS9_CRC2)) - return 1; - - return 0; -} - -int os9_header(OS9_MODULE_t *mod) -{ - u_char tmp = 0x00; - u_char *ptr = (u_char *) mod; - int i; - - for (i = 0; i < OS9_HEADER_SIZE; i++) - tmp ^= *(ptr++); - - return tmp; -} diff -r 03a26438ab8d -r f20bf9874697 src/os9/level1/Makefile --- a/src/os9/level1/Makefile Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ - -OS9SRC = ../nitros9-code -SRCDIR = $(OS9SRC)/level1/modules -SRCCMD = $(OS9SRC)/level1/cmds -SRCDIR2 = $(OS9SRC)/level2/modules - -A09 = ../../a09 -I $(OS9SRC)/defs/ - -MOD = pdisk init os9p1 os9p2 ioman pipe piper rbf scf term pty d0 d1 vrbf v0 clock shell dir mdir sysgo shell - -all : ${MOD} - cd cmds; make - -clean : - cd cmds; make clean - rm -f $(MOD) *.lst krn.asm - -LST = -l $@.lst - -# our own module for sbc09 -# CoCoOS9's level1/os9p1.asm has wrong vector value, use our own - -pdisk : - $(A09) pdisk.asm -o pdisk $(LST) - -#boot : boot.asm -# $(A09) boot.asm -o boot $(LST) - -init : init.asm - $(A09) ${SRCDIR}/init.asm -o $@ $(LST) -# $(A09) init.asm -o init $(LST) - -pty : pty.asm - $(A09) pty.asm -o pty $(LST) - -term : pty-dd.asm - $(A09) pty-dd.asm -o term $(LST) - -d0 : d0.asm - $(A09) d0.asm -o d0 $(LST) - -d1 : d1.asm - $(A09) d1.asm -o d1 $(LST) - -clock : clock.asm - $(A09) clock.asm -o clock $(LST) - -vrbf : - $(A09) ../level2/vrbf.asm -o $@ $(LST) - -v0 : - $(A09) v0.asm -o $@ $(LST) - -# os9 level1 moduels - -shell : $(SRCCMD)/shell_21.asm - $(A09) $< -o $@ $(LST) - -mdir : ${SRCCMD}/mdir.asm - $(A09) $< -o $@ $(LST) - -dir : ${SRCCMD}/dir.asm - $(A09) ${SRCCMD}/dir.asm -o dir $(LST) - -os9p1 : - cat ${OS9SRC}//defs/coco.d ${SRCDIR}/kernel/krn.asm > krn.asm - $(A09) -I ../nitros9-code/level1/modules/kernel/ krn.asm -o os9p1 $(LST) - -os9p2 : - $(A09) ${SRCDIR}/kernel/krnp2.asm -o os9p2 $(LST) - -sysgo : - $(A09) sysgo.asm -o sysgo $(LST) - -ioman : - $(A09) ${SRCDIR}/ioman.asm -o ioman $(LST) - -pipe : - $(A09) ${SRCDIR}/pipe.asm -o pipe $(LST) - -piper : - $(A09) ${SRCDIR}/piper.asm -o piper $(LST) - -rbf : - $(A09) ${SRCDIR}/rbf.asm -o rbf $(LST) - -scf : - $(A09) ${SRCDIR}/scf.asm -o scf $(LST) - diff -r 03a26438ab8d -r f20bf9874697 src/os9/level1/clock.asm --- a/src/os9/level1/clock.asm Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -******************************************************************** -* Clock - OS-9 Level One V2 Clock module -* -* $Id: clock.asm,v 1.1.1.1 2001/02/21 23:30:52 boisy Exp $ -* -* NOTE: This clock is TOTALLY VALID for ALL DATES between 1900-2155 -* -* Ed. Comments Who YY/MM/DD -* ------------------------------------------------------------------ -* 5 Tandy/Microware original version -* 6 Modified to handle leap years properly for BGP 99/05/03 -* 1900 and 2100 A.D. - - nam Clock - ttl OS-9 Level One V2 Clock module - - ifp1 - use defsfile - endc - -tylg set Systm+Objct -atrv set ReEnt+rev -rev set $01 -edition set $06 -TimerPort set $e030 -TkPerSec set 60 -TkPerTS equ TkPerSec/10 ticks per time slice - - - mod eom,name,tylg,atrv,ClkEnt,size - -size equ . - -name fcs /Clock/ - fcb edition - -SysTbl fcb F$Time - fdb FTime-*-2 - fcb $80 - - -ClockIRQ ldx #TimerPort - lda ,x - bita #$10 - bne L00B4 -L00AE jsr [>D.Poll] poll ISRs - bcc L00AE keep polling until carry set - jmp [>D.AltIRQ] jump into an alternate IRQ if available - -L00B4 - ldb #$8f start timer - stb ,x - - dec D.Clock] - -ClkEnt equ * - ldd #59*256+$01 last second and last tick - std PIA0Base+3 -* nop -* nop -* sta >$FFDF turn off ROM mode -* jmp >Bt.Start+2 jump to boot -* BasicRL equ *-BasicRst - ENDC - ENDC - -Init fcs /Init/ - -* Entry: X = pointer to start of nul terminated string -* Exit: D = length of string -strlen pshs x - ldd #-1 -go@ addd #$0001 - tst ,x+ - bne go@ - puls x,pc - -* Display carriage-return/line-feed. -WriteCR pshs y - leax CrRtn,pcr - ldy #$0001 - os9 I$WritLn - puls y,pc - -********************************************************** -* SysGo Entry Point -********************************************************** -start leax >IcptRtn,pcr - os9 F$Icpt -* Set priority of this process - os9 F$ID - ldb #DefPrior - os9 F$SPrior - -* Write OS name and Machine name strings - leax Init,pcr - clra - pshs u - os9 F$Link - bcs SignOn - stx Banner,pcr - ldy #BannLen - lda #$01 standard output - os9 I$Write write out banner - -* Set default time and start Clock module - leax >DefTime,pcr - os9 F$STime set time to default - - IFEQ 1 - leax >MDIR,pcr - leau >mdirprm,pcr - ldd #$0100 - ldy #$0003 - os9 F$Fork - bcs mdirend AutoEx failed.. - os9 F$Wait - ldu ,s - bra mdirend -MDIR fcc "mdir" - fcb $0d -mdirprm fcc "-e" - fcb C$CR -mdirend - ldu ,s - ENDC - -* IFEQ ROM -* Change EXEC and DATA dirs - leax >ExecDir,pcr - lda #EXEC. - os9 I$ChgDir change exec. dir - leax >DefDev,pcr -* Made READ. so that no write occurs at boot (Boisy on Feb 5, 2012) - lda #READ. - os9 I$ChgDir change data dir. - bcs L0125 -* leax >HDDev,pcr -* lda #EXEC. -* os9 I$ChgDir change exec. dir to HD -* ENDC - -L0125 equ * - IFEQ atari+corsham - IFEQ Level-1 -* Setup BASIC code (CoCo port only) -* leax >BasicRst,pcr -* ldu #D.CBStrt -* ldb #BasicRL -*CopyLoop lda ,x+ -* sta ,u+ -* decb -* bne CopyLoop - ELSE - os9 F$ID get process ID - lbcs L01A9 fail - leax ,u - os9 F$GPrDsc get process descriptor copy - lbcs L01A9 fail - leay ,u - ldx #$0000 - ldb #$01 - os9 F$MapBlk - bcs L01A9 - -* lda #$55 set flag for Color BASIC -* sta Shell,pcr -* leau >Startup,pcr -* ldd #256 -* ldy #StartupL -* os9 F$Fork -* bcs DoAuto Startup failed.. -* os9 F$Wait -* ENDC - -* Fork AutoEx here -*DoAuto leax >AutoEx,pcr -* leau >CRtn,pcr -* ldd #$0100 -* ldy #$0001 -* os9 F$Fork -* bcs L0186 AutoEx failed.. -* os9 F$Wait - -L0186 equ * - ldu ,s -FrkShell leax >ShellPrm,pcr - leay ,u - ldb #ShellPL -L0190 lda ,x+ - sta ,y+ - decb - bne L0190 -* Fork final shell here - leax >Shell,pcr - lda #$01 D = 256 (B already 0 from above) - ldy #ShellPL - IFGT Level-1 - os9 F$Chain Level 2/3. Should not return.. - ldb #$06 it did! Fatal. Load error code - bra Crash - -L01A9 ldb #$04 error code -Crash clr >DPort+$08 turn off disk motor - jmp TimerPort - jmp [>D.Clock] - -TkPerTS equ 2 - -ClkEnt equ * - pshs cc - orcc #FIRQMask+IRQMask mask ints - leax >ClockIRQ,pcr - stx ClockFIRQ,pcr - stx $FFF6 must be a RAM - endc -* install system calls - leay >SysTbl,pcr - os9 F$SSvc - ldd #59*256+TkPerTS last second and time slice in minute - std basic.asm - -basic.s : basic.asm - $(A09) -l $@.lst -s $@ basic.asm - -mdir : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -mfree : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -proc : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -procs : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -reboot : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -smap : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -mmap : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -pmap : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm -dmem : - $(A09) -l $@.lst -o $@ $(SRC2)/$@.asm - -asm : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -attr : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -calldbg : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -cmp : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -config : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -copy : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -cputype : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -date : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -debug : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -del : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -deldir : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -devs : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -dir : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -dir_cb : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -dirsort : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -disasm : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -dump : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -dw.as : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -echo : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -edit : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -error : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -free : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -help : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -ident : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -irqs : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -link : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -list : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -load : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -login : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -makdir : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -pxd : - $(A09) -D PXD -l $@.lst -o $@ $(SRC1)/pd.asm -pwd : - $(A09) -D PWD -l $@.lst -o $@ $(SRC1)/pd.asm -prompt : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -shellplus : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -sleep : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -tee : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -touch : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -tsmon : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm -unlink : - $(A09) -l $@.lst -o $@ $(SRC1)/$@.asm diff -r 03a26438ab8d -r f20bf9874697 src/os9/level2/cmds/defsfile --- a/src/os9/level2/cmds/defsfile Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -* Main defsfile for OS-9 Level One V1 -* - use ../defsfile diff -r 03a26438ab8d -r f20bf9874697 src/os9/level2/cmds/fixbasic.pl --- a/src/os9/level2/cmds/fixbasic.pl Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#!/usr/bin/perl -# - -while(<>) { - next if (/^ACIA/ .. /^TDRE/) ; - next if (/^TSTBRK/ .. /^ END/) ; - if (/^CLEAR/) { -print <<"EOFEOF" - JSR \$24 ;; echo off (but it is not suuported on pty.asm ) -EOFEOF - } - if (/^GL02/) { - print "GL02\n"; # do not echo input - next; - } - print; -} - - -print <<"EOFEOF" -****************************** -****************************** -TSTBRK bsr BRKEEE - bcc GETC05 -GETCHR bsr INEEE - CMPA \#ETX ; 3 - BNE GETC05 - JMP BREAK -INTEEE -GETC05 RTS -PUTCHR INC ZONE - JMP OUTEEE -****************************** -****************************** -INEEE PSHS D - JSR 0 - STB ,S - PULS D,PC -OUTEEE PSHS D - TFR A,B - JSR 3 - PULS D,PC -BRKEEE PSHS D - JSR \$F - PULS D,PC -****************************** -****************************** - END -EOFEOF diff -r 03a26438ab8d -r f20bf9874697 src/os9/level2/cmds/loop.asm --- a/src/os9/level2/cmds/loop.asm Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -******************************************************************** -* loop dummy loader -* -* $Id$ -* -* Edt/Rev YYYY/MM/DD Modified by -* Comment -* ------------------------------------------------------------------ -* 1 2018/07/30 S. Kono - - nam Loop - ttl Dummy loop - - ifp1 - use defsfile - endc - -* Module header definitions -tylg set Prgrm+Objct -atrv set ReEnt+rev -rev set $00 -edition set 1 - - mod eom,name,tylg,atrv,start,size - - org 0 -count rmb 2 -size equ . - -name fcs /Loop/ - fcb edition - -start ldy #4000 -l1 ldx #0 -l0 leax -1,x - bne l0 - leay -1,y - bne l1 -Exit clrb - os9 F$Exit - - - emod -eom equ * - end diff -r 03a26438ab8d -r f20bf9874697 src/os9/level2/cmds/sbc09.asm --- a/src/os9/level2/cmds/sbc09.asm Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,264 +0,0 @@ -******************************************************************** -* sbc09 emulator -* -* $Id$ -* -* Edt/Rev YYYY/MM/DD Modified by -* Comment -* ------------------------------------------------------------------ -* 1 2018/08/20 S. Kono -* Emulatoe sbc09 on os9 lv2 - - nam Sbc09 - ttl Sbc09 emulator - - ifp1 - use defsfile - endc - -* Module header definitions -tylg set Prgrm+Objct -atrv set ReEnt+rev -rev set $00 -edition set 1 - - mod eom,name,tylg,atrv,start,size - - org 0 -ioentry rmb $80 -filepath rmb 2 -parmptr rmb 2 -stdin rmb 1 -chksum rmb 1 -bcount rmb 1 -adr rmb 2 -work rmb 2 -readbuff rmb $100 - org $400 -emstart rmb $e000-. -size equ . - -name fcs /Sbc09/ - fcb edition - -start - clr PIA0Base+3 -* nop -* nop -* sta >$FFDF turn off ROM mode -* jmp >Bt.Start+2 jump to boot -* BasicRL equ *-BasicRst - ENDC - ENDC - -Init fcs /Init/ - -* Entry: X = pointer to start of nul terminated string -* Exit: D = length of string -strlen pshs x - ldd #-1 -go@ addd #$0001 - tst ,x+ - bne go@ - puls x,pc - -* Display carriage-return/line-feed. -WriteCR pshs y - leax CrRtn,pcr - ldy #$0001 - os9 I$WritLn - puls y,pc - -********************************************************** -* SysGo Entry Point -********************************************************** -start leax >IcptRtn,pcr - os9 F$Icpt -* Set priority of this process - os9 F$ID - ldb #DefPrior - os9 F$SPrior - -* Write OS name and Machine name strings - leax Init,pcr - clra - pshs u - os9 F$Link - bcs SignOn - stx Banner,pcr - ldy #BannLen - lda #$01 standard output - os9 I$Write write out banner - -* Set default time - leax >DefTime,pcr - os9 F$STime set time to default - - IFEQ ROM -* Change EXEC and DATA dirs - leax >ExecDir,pcr - lda #EXEC. - os9 I$ChgDir change exec. dir - leax >DefDev,pcr -* Made READ. so that no write occurs at boot (Boisy on Feb 5, 2012) - lda #READ. - os9 I$ChgDir change data dir. - bcs L0125 -* leax >HDDev,pcr -* lda #EXEC. -* os9 I$ChgDir change exec. dir to HD - ENDC - -L0125 equ * - pshs u,y - IFEQ atari+corsham - IFEQ Level-1 -* Setup BASIC code (CoCo port only) -* leax >BasicRst,pcr -* ldu #D.CBStrt -* ldb #BasicRL -*CopyLoop lda ,x+ -* sta ,u+ -* decb -* bne CopyLoop - ELSE - os9 F$ID get process ID - lbcs L01A9 fail - leax ,u - os9 F$GPrDsc get process descriptor copy - lbcs L01A9 fail - leay ,u - ldx #$0000 - ldb #$01 - os9 F$MapBlk - bcs L01A9 - -* lda #$55 set flag for Color BASIC -* sta Shell,pcr -* leau >Startup,pcr -* ldd #256 -* ldy #StartupL -* os9 F$Fork -* bcs DoAuto Startup failed.. -* os9 F$Wait -* ENDC - -* Fork AutoEx here -*DoAuto leax >AutoEx,pcr -* leau >CRtn,pcr -* ldd #$0100 -* ldy #$0001 -* os9 F$Fork -* bcs L0186 AutoEx failed.. -* os9 F$Wait - - IFEQ Level-1 - leax >MDIR,pcr - leau >mdirprm,pcr - ldd #$0100 - ldy #$0003 - os9 F$Fork - bcs L0186 AutoEx failed.. - os9 F$Wait - bra L0186 -MDIR fcs "mdir" - fcb $0d - ENDC -L0186 equ * - puls u,y -FrkShell leax >ShellPrm,pcr - leay ,u - ldb #ShellPL -L0190 lda ,x+ - sta ,y+ - decb - bne L0190 -* Fork final shell here - leax >Shell,pcr - lda #$01 D = 256 (B already 0 from above) - ldy #ShellPL - IFGT Level-1 - os9 F$Chain Level 2/3. Should not return.. - ldb #$06 it did! Fatal. Load error code - bra Crash - -L01A9 ldb #$04 error code -Crash clr >DPort+$08 turn off disk motor - jmp -#include -#include -#include - -// #define DEBUG 1 - -/* - * Level1 - * os9p1 should be 0xf800 - * it searches ram from the beginning - * rom modules are searched from just after the end of RAM - * - * Level2 - * Coco 512kb memory space - * last 8k is a ROM (can be switched?) ( block 0x3f ) - * os9p1 search module on 0x0d00~0x1e00 at block 0x3f - * - * 8k block ( offset 0xc000 ) - * - * 0xe000 - 0xccff 0xff - * 0xed00 - 0xfeff os9 modules, os9p1 should be the last - * MMU doesnot touch below - * 0xff80 - 0xffdf IO port ( ACIA, clock, pdisk, MMU ) - * 0xffd0 - 0xffef boot code - * 0xfff0 - 0xffff intr vector - * ... next few blocks as extended ROM - * lv2 6809 memory check routine destroys 0x200 on page 0x40 - * sta >-$6000,x - * avoid 0x200 - * - */ - -int level = 1; -int IOBASE = 0xe000; -int IOSIZE = 0x100; -char * outfile ; - -#define LV2START 0xffd0 // our own small boot for mmu -#define LV2ROMEND 0xff80 - -// #define DEBUG - -typedef struct os9module { - int size; - int entry; - int location; - int ioflag; - unsigned char *mod; - char *name; - struct os9module *next; -} *MPTR ; - -unsigned short vec[8]; - -struct os9module * -readOS9module(char *filename) -{ - FILE *fp = fopen(filename,"rb"); - if (fp==0) { - fprintf(stderr,"cannot read %s\n",filename); - exit(1); - } - struct stat st; - fstat(fileno(fp),&st); - int size = st.st_size; - struct os9module *m = malloc(size + sizeof(struct os9module)); - m->size = size; - m->next = 0; - m->ioflag = 0; - m->mod = (unsigned char*)m + sizeof(struct os9module); - fread(m->mod , size, 1, fp); - m->name = (char*) (m->mod + (m->mod[4]*256 + m->mod[5]) ); - m->entry = m->mod[9]*256 + m->mod[10] ; - fclose(fp); - return m; -} - -void -fputword(unsigned short x, FILE *fp) -{ - fputc((x>>8)&0xff,fp); - fputc(x&0xff,fp); -} - -void printOs9Str(char *p) -{ - char *q = p; - while((*p & 0x80)==0) { - putchar(*p); - p++; - } - putchar(*p & 0x7f); - while(p>8; - adr[1] = vec&0xff; - adr += 2; - } -} - -int search_vector(MPTR m) { - unsigned char v[] = { 0x6E, 0x9F, 0x00, 0x2C, 0x6E}; - for( unsigned char *p = m->mod ; p < m->mod + m->size; p++ ) { - int i=0; - for(; i< sizeof(v); i++) { - if (p[i]!=v[i]) break; - } - if (i==sizeof(v)) - return p - m->mod; - } - return 0; -} - -// calcurate position from the botton -// avoid v09 IO map on 0xe000-0xe800 -// os9p1 have to be last and at 0xf800 -int findLocation(MPTR m, int loc) { - if (m==0) return loc; - int top = findLocation(m->next, loc) - m->size; - if (m->next==0) { - if (level == 1) - if (m->size > 0xff80-0xf800 ) { - top = 0x10000-(m->size+0x80); - } else { - top = 0xf800; // OS9p1 - } - else { -#if 0 - // old level2 kernel has vector at the bottom - top = 0x10000-(m->size+0x80); - rewrite_vector(m,m->size,m->mod+getword(m->mod+2),7); -#else - top = 0xf000; // level2 OS9p1 starts here - // and theses area are RAM /REGISTER STACK/ -#endif - } - } - if (level==1 && !(( top+m->size < IOBASE ) || ( IOBASE+IOSIZE < top)) ) { - top = IOBASE-m->size-1; - m->ioflag = 1; -#ifdef DEBUG - printf("*"); -#endif - } else if (level==2 && 0xed00 > top) { - m->ioflag = 1; - } - m->location = top; -#ifdef DEBUG - printf("mod "); - printOs9Str(m->name); - printf(" \t: 0x%x - 0x%x\n",top, top + m->size); -#endif - return top; -} - -int -main(int ac, char *av[]) -{ - int vectable = 0; - struct os9module *m = 0, root ; - root.size = 0; - root.mod = 0; - m = &root; - - for(int i = 1 ; inext = cur; - m = cur; - } - - FILE *romfile; - unsigned pos; - if (outfile==0) return 1; - - romfile=fopen(outfile,"wb"); - if(!romfile) { - fprintf(stderr,"Cannot create file %s\n",av[1]); - exit(1); - } - - - int start = findLocation(root.next,0); - start = start&0xf800; - printf("\n\n"); - - if (level==2) { - for(int i=0; i<0xd00; i++) fputc(0xff,romfile); - pos = 0xed00; - } else { - pos = start; - } - int ofs = 0; - struct os9module *os9p1 = 0; - for(struct os9module *cur = root.next; cur ; cur = cur->next ) { - if ( level==2 && cur->ioflag ==1) continue; - // last module have to os9p1 - if ( cur->next == 0 ) { - os9p1 = cur; - if ( level==1 ) { - if (os9p1->size > 0x07f0) { - ofs = (os9p1->size+0xf)&0xfff0; - ofs -= 0x07f0; - } - for(; pos < 0xf800-ofs ; pos++) { // os9p1 begins at 0xf800 - fputc(0xff,romfile); - } - } else { -#if 0 - int pend = 0x10000-( cur->size +0x80); - for(; pos < pend ; pos++) { // os9p1 ends 0xff7f - fputc(0xff,romfile); - } -#endif - for(; pos < 0xf000 ; pos++) { // level2 os9p1 start from 0xf000 - fputc(0xff,romfile); - } - } - } - printf("mod "); - printOs9Str(cur->name); - cur->location = pos; - fwrite(cur->mod, cur->size, 1, romfile); - printf(" \t: 0x%x - 0x%x size 0x%04x entry 0x%x\n",pos, pos + cur->size-1,cur->size,cur->entry+cur->location); -#ifdef DEBUG - printf(" \t: 0x%x \n",cur->location); - printf(" \t: 0x%x - 0x%x : 0x%lx \n",pos, pos + cur->size, ftell(romfile)+start); -#endif - pos = pos+cur->size; - if (level==1 && cur->ioflag) { - if (level==1) { - for(; pos < IOBASE + IOSIZE; pos++) { - fputc(0xff,romfile); - } - printf("*"); - } - } - } - printf("os9 end %x\n",pos); - if (level==1) { - vectable = 0x10000 - 2*7; - for( ; poslocation +vecofs+perm[i]*4,romfile); - } - int entry_ofs = (m->mod[9]<<8) + m->mod[10]; - fputword( os9p1->location + entry_ofs ,romfile); - // printf("os9p1 location ofs %0x\n", os9p1->location); - // printf("vector ofs %0x\n", vecofs); - // printf("reset ofs %0x\n", entry_ofs); - } else { - fputword(0xF82d-ofs,romfile); - fputword(0xF831-ofs,romfile); - fputword(0xF835-ofs,romfile); - fputword(0xF839-ofs,romfile); - fputword(0xF83d-ofs,romfile); - fputword(0xF841-ofs,romfile); - fputword(0xF876-ofs,romfile); - } - } else { - char vector[] = "level2/vector"; - FILE *fp = fopen(vector,"rb"); - if (fp==0) { - fprintf(stderr,"cannot read %s\n",vector); - exit(1); - } - for( ; poslocation); -#endif - printf("os9entry %x\n",os9p1->location+getword(os9p1->mod+9)); - - fputword(os9p1->location+getword(os9p1->mod+9),romfile); // os9p1 entry point - unsigned short vec = os9p1->location+os9p1->size - 18; - fputword(vec,romfile); - fputword(vec+3,romfile); - fputword(vec+6,romfile); - - fputword(vec+9,romfile); - fputword(vec+12,romfile); - fputword(vec+15,romfile); - fputword(LV2START,romfile); - - pos = 0x10000; - int bootsize = 2; - for(struct os9module *cur = root.next; cur ; cur = cur->next ) { - if ( cur->ioflag ==0) continue; - bootsize += cur->size; - } - bootsize += 0x300-2; // to avoid 0x200 bombing - fputc(bootsize>>8,romfile); - fputc(bootsize&0xff,romfile); - pos += 2; - for( int i = 0; i<0x300-2; i++) fputc(0xff,romfile); - for(struct os9module *cur = root.next; cur ; cur = cur->next ) { - if ( cur->ioflag ==0) continue; - cur->location = pos; - printf("mod "); - printOs9Str(cur->name); - fwrite(cur->mod, cur->size, 1, romfile); - printf(" \t: 0x%x - 0x%x size 0x%04x entry 0x%x\n",pos, pos + cur->size-1, cur->size, cur->entry+cur->location); -#ifdef DEBUG - printf(" \t: 0x%x \n",cur->location); - printf(" \t: 0x%x - 0x%x : 0x%lx \n",pos, pos + cur->size, ftell(romfile)+start); -#endif - pos += cur->size; - } - while(pos++ & 0xff) fputc(0xff,romfile); - } - if (level==1) - printf("boot rom from 0x%lx\n",0x10000-ftell(romfile)); - else { - long size; - printf("boot rom from 0xc000 size 0x%lx\n",(size=ftell(romfile))); - if (size > 0x4d00 + 0x2000) { - printf(" was too big. make it less than 0x6d00\n"); - } - } - fclose(romfile); - return 0; -} - - diff -r 03a26438ab8d -r f20bf9874697 src/os9/os9.h --- a/src/os9/os9.h Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -typedef unsigned char u_char; - -typedef struct os9_module_t { - u_char id[2]; - u_char size[2]; - u_char name[2]; - u_char tyla; - u_char atrv; - u_char parity; - union { - u_char data[1]; /* plain modules */ - struct { - u_char exec[2]; - u_char data[1]; - } system; - struct { - u_char exec[2]; - u_char mem[2]; - u_char data[1]; - } program; - struct { - u_char exec[2]; - u_char mem[2]; - u_char mode[1]; - u_char data[1]; - } driver; - struct { - u_char exec[2]; - u_char data[1]; - } file_mgr; - struct { - u_char fmgr[2]; - u_char driver[2]; - u_char mode; - u_char port[3]; - u_char opt; - u_char dtype; - u_char data[1]; - } descriptor; - } data; -} OS9_MODULE_t; - -#define OS9_HEADER_SIZE 9 - -#define TYPE_MASK 0xF0 -typedef enum os9_type_t { - NULL_TYPE = 0, - Prgrm, - Sbtrn, - Multi, - Data, - SSbtrn, - TYPE_6, - TYPE_7, - TYPE_8, - TYPE_9, - TYPE_A, - TYPE_B, - Systm, - FlMgr, - Drivr, - Devic -} OS9_TYPE_t; - -#define LANG_MASK 0x0F -typedef enum os9_lang_t { - NULL_LANG = 0, - Objct, - ICode, - PCode, - CCode, - CblCode, - FrtnCode, - Obj6309, -} OS9_LANG_t; - -#define ATTR_MASK 0xF0 -typedef enum os9_attr_t { - ReEnt = 0x80, - Modprot = 0x40, -} OS9_attr_t; - -#define REVS_MASK 0x0F - -#define OS9_ID0 0x87 -#define OS9_ID1 0xcd - -#define OS9_CRC0 0x80 -#define OS9_CRC1 0x0F -#define OS9_CRC2 0xE3 - -#define INT(foo) (foo[0] * 256 + foo[1]) -int os9_crc(OS9_MODULE_t *mod); -int os9_header(OS9_MODULE_t *mod); diff -r 03a26438ab8d -r f20bf9874697 src/os9/os9mod.c --- a/src/os9/os9mod.c Sun Sep 16 20:30:15 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +0,0 @@ -#include -#include -#include -#include -#include "os9.h" - - -u_char *os9_string(u_char *string); -void ident(OS9_MODULE_t *mod); -void usage(void); -long pos; - -static char *types[16] = { - "???", "Prog", "Subr", "Multi", "Data", "USR 5", "USR 6", "USR 7", - "USR 8", "USR 9", "USR A", "USR B", "System", "File Manager", - "Device Driver", "Device Descriptor" -}; - -static char *langs[16] = { - "Data", "6809 Obj", "Basic09 I-Code", "Pascal P-Code", "C I-Code", - "Cobol I-Code", "Fortran I-Code", "6309 Obj", "???", "???", "???", - "???", "???", "???", "???", "???" -}; - -int offset = 0; - -int main(int argc, char **argv) -{ - char *filename = NULL; - FILE *fp; - u_char buffer[65536]; /* OS9 Module can't be larger than this */ - OS9_MODULE_t *mod = (OS9_MODULE_t *) buffer; - int i=0, j; - int flag = 0; - - argv++; /* skip my name */ - - if (argc == 1) - usage(); - - while ((argc >= 2) && (*argv[0] == '-')) { - if (*(argv[0] + 1) == 's') { - argc--; - flag = 1; - } else if (*(argv[0] + 1) == 'o') { - argc--; argc--; - argv++; - offset = strtol(argv[0],(char**)0,0); - } else - usage(); - argv++; - } - - - while (argc-- > 1) { - if (*argv==0) return 0; - filename = *(argv++); - - if ((fp = fopen(filename,"rb")) == NULL) { - fprintf(stderr, "Error opening file %s: %s\n", - filename, strerror(errno)); - return 1; - } - - while (!feof(fp)) { - - if (flag) { - int c; - while( !feof(fp) && (c = fgetc(fp)) != 0x87 ); - ungetc(c, fp); - } - - pos = ftell(fp); - if (fread(buffer, OS9_HEADER_SIZE, 1, fp) != 1) { - if (feof(fp)) - break; - else { - fprintf(stderr, "Error reading file %s: %s\n", - filename, strerror(errno)); - return 1; - } - } - - if ((mod->id[0] != OS9_ID0) && (mod->id[1] != OS9_ID1)) { - fprintf(stderr,"Not OS9 module, skipping.\n"); - return 1; - } - - if ((i = os9_header(mod))!=0xff) { - fprintf(stderr, "Bad header parity. Expected 0xFF, got 0x%02X\n", i); - return 1; - } - - i = INT(mod->size) - OS9_HEADER_SIZE; - if ((j = fread(buffer + OS9_HEADER_SIZE, 1, i, fp)) != i) { - fprintf(stderr,"Module short. Expected 0x%04X, got 0x%04X\n", - i + OS9_HEADER_SIZE, j + OS9_HEADER_SIZE); - return 1; - } - ident(mod); - } - fclose(fp); - } - return 0; - -} - -void ident(OS9_MODULE_t *mod) -{ - int i, j; - u_char *name, *ptr, tmp, *buffer = (u_char *) mod; - - i = INT(mod->name); - j = INT(mod->size); - name = os9_string(&buffer[i]); - printf("Offset : 0x%04lx\n", pos + offset); - printf("Header for : %s\n", name); - printf("Module size: $%X #%d\n", j, j); - ptr = &buffer[j - 3]; - printf("Module CRC : $%02X%02X%02X (%s)\n", ptr[0], ptr[1], ptr[2], - os9_crc(mod) ? "Good" : "Bad" ); - printf("Hdr parity : $%02X\n", mod->parity); - - switch ((mod->tyla & TYPE_MASK) >> 4) - { - - case Drivr: - case Prgrm: - i = INT(mod->data.program.exec); - printf("Exec. off : $%04X #%d\n", i, i); - i = INT(mod->data.program.mem); - printf("Data size : $%04X #%d\n", i, i); - break; - - case Devic: - printf("File Mgr : %s\n", - os9_string(&buffer[INT(mod->data.descriptor.fmgr)])); - printf("Driver : %s\n", - os9_string(&buffer[INT(mod->data.descriptor.driver)])); - break; - - case NULL_TYPE: - case TYPE_6: - case TYPE_7: - case TYPE_8: - case TYPE_9: - case TYPE_A: - case TYPE_B: - case Systm: - break; - } - - - - - tmp = buffer[i + strlen((const char *)name)]; - printf("Edition : $%02X #%d\n", tmp, tmp); - printf("Ty/La At/Rv: $%02X $%02x\n", mod->tyla, mod->atrv); - printf("%s mod, ", types[(mod->tyla & TYPE_MASK) >> 4]); - printf("%s, ", langs[mod->tyla & LANG_MASK]); - printf("%s, %s\n", (mod->atrv & ReEnt) ? "re-ent" : "non-share", - (mod->atrv & Modprot) ? "R/W" : "R/O" ); - printf("\n"); -} - -u_char *os9_string(u_char *string) -{ - static u_char cleaned[80]; /* strings shouldn't be longer than this */ - u_char *ptr = cleaned; - int i = 0; - - while (((*(ptr++) = *(string++)) < 0x7f) && - (i++ < sizeof(cleaned) - 1)) - ; - - *(ptr - 1) &= 0x7f; - *ptr = '\0'; - return cleaned; -} -void usage(void) -{ - printf("Usage: os9mod [-s] [-o offset] file [ file ... ]\n"); - printf("Performs an OS-9: 6809 'ident' on the specified files.\n"); - printf(" -s : skip to valid module\n"); - printf(" -o : offset \n\n"); - exit(0); -}