Enterprise Forever

:UK => Programming => Topic started by: BruceTanner on 2016.February.08. 19:13:31

Title: .com file for IS-BASIC *and* IS-DOS
Post by: BruceTanner on 2016.February.08. 19:13:31
There is an unfortunate convention that "header type 5" EXOS applications and IS-DOS applications both use ".COM" files. So I wanted my program to work when loaded both ways.

EXOS loads the type 5 .com program into memory at 100h and jumps to it. IS-DOS loads the header itself at 100h followed by the program and then jumps to 100h :( So I needed to make the header executable! :shock:

The first header byte is 0, which is a NOP :)
The next header byte is 5, the type byte. 05 is DEC B, so harmless. :)
The next byte is the low byte of the program size. So I padded the end of the program with 0s until it was xx3eh bytes long. 3e is LD A,n :mrgreen: :lol:
The next byte is the high byte of the program size which will be loaded into A by the LD A,n instruction :)
Normally we then 12 0s (NOP), but I used 11 0s and a final opcode byte
Instead of 0 the last byte is 21h = LD HL,n

The program code then follows the header.

The first instruction in the code is a two-byte JR instruction, so this will be skipped when the above header is executed as it will be loaded into HL but not when loaded as a type 5 program as this is EXOS's entry point. This allows the program to detect if it was loaded by IS-DOS. It needs to do this because in this case it needs to do an EXOS reset instruction, mess about with paging a bit to get it compatible with an EXOS type 5 load, and also to copy the main program down in memory by 16 bytes, overwriting the header.

The final "trick" is to do the copy by putting an LDIR instruction at 0feh and jumping to it. When it has finished the next instruction will be the JR at the start. :)

Source code enclosed :lol: :lol: :lol:

B.
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: Zozosoft on 2016.February.08. 21:31:25
Nice trick! :smt038
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: lgb on 2016.February.08. 23:53:46
Wow :)

It would be nice to handle x86/DOS as well, so DOS or even Windows :) users (in DOS window) won't execute is, or at least it would print "Get an EP, dude!" with DOS :) Crazy enough, without too much real value, however your IS-DOS (CP/M) / EXOS separation is much more a real headache compared to this, nice work! :)
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: BruceTanner on 2016.February.09. 00:28:01
It would be nice to handle x86/DOS as well

:lol: I didn't think of that...interesting challenge!: write some opcodes that do something useful on both a Z80 and x86! :twisted:

For some reason lots of common z80 opcodes stuck in my mind from 30 years ago, like 21h=LD HL,n and 3eh=LD A,n, but I cannot recall even one x86 opcode even though I spent just as many years doing x86 assembly.
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: lgb on 2016.February.09. 00:45:23
:lol: I didn't think of that...interesting challenge!: write some opcodes that do something useful on both a Z80 and x86! :twisted:

There were tries even here in the forum, if I remember correctly. However the hard part now: do it in a way, that it can be executed on CP/M, EXOS, and x86/DOS :) Now that's quite hard, I guess. CP/M and x86 is not so much a problem. But EXOS header is ugly on x86 treated as opcodes, the "00 05" at the beginning would be add (di), al and even "00 00" (so not a single 00 as with Z80/8080) is add (bx+si),al. Since we can't (?) know what the initial states of BX, SI and DI registers on x86, it can be a big problem.

DOS came into my mind only, because if ".COM" - as extension - is confusing (IS-DOS vs EXOS), DOS can be a problem too :) It has also got .COM files, well, originated from CP/M how surprising, but not the 8080 version of the CP/M ...
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: gflorez on 2016.February.09. 01:06:00
This new header deserves a suitable name:

Hibrid, mixed, composite, executable, combined, alloy, etc

Very ingenious!
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: Zozosoft on 2016.February.09. 07:26:19
There were tries even here in the forum, if I remember correctly.
Povi do it, it is run on IS-DOS, and on PC write this: "This program requires ENTERPRISE 128 computer with IS-DOS"
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: IstvanV on 2016.February.09. 10:20:01
Povi do it, it is run on IS-DOS, and on PC write this: "This program requires ENTERPRISE 128 computer with IS-DOS"

There is a similar trick in z88dk (enterprise_crt0.asm):
Code: ZiLOG Z80 Assembler
  1. start:
  2. IF (startup=2)
  3. IF !DEFINED_noprotectmsdos
  4.         ; This protection takes little less than 50 bytes
  5.         defb    $eb,$04         ;MS DOS protection... JMPS to MS-DOS message if Intel
  6.         ex      de,hl
  7.         jp      begin           ;First decent instruction for Z80, if survived up to here !
  8.         defb    $b4,$09         ;DOS protection... MOV AH,9 (Err msg for MS-DOS)
  9.         defb    $ba
  10.         defw    dosmessage      ;DOS protection... MOV DX,OFFSET dosmessage
  11.         defb    $cd,$21         ;DOS protection... INT 21h.
  12.         defb    $cd,$20         ;DOS protection... INT 20h.
  13.  
  14. dosmessage:
  15.         defm    "This program is for the Enterprise computer."
  16.         defb    13,10,'$'
  17.  
  18. begin:
  19. ENDIF
  20. ENDIF
Title: Re: .com file for IS-BASIC *and* IS-DOS
Post by: Povi on 2016.February.10. 16:40:50
Povi do it, it is run on IS-DOS, and on PC write this: "This program requires ENTERPRISE 128 computer with IS-DOS"
Another good trick is a simple hello world program, which do the same thing (writes Hello World - what a surprise) on IS-DOS (CP/M) and on x86 DOS.
the code is here:
http://povi.uw.hu/hello_world/hello_world.html

sorry, the article on Hungarian