Z80 Assembly programming for the Elan Enterprise 128

What is the Enterprise 128?
The Enterprise 128 is an 8 bit Z80 system, it's comparable to the Amstrad CPC,however it has more advanced Memory Mapping which allows more flexible bank switching, and more advanced graphics

Like the CPC screen it can function at 320x200 at 4 colors, and you can halve the resolution to get 160x200 with 16 colors... unlike the CPC, there is a 256 color mode of 80x200
All these modes can be 'half resolution' of 100 vertical pixels

The Enterprise doesn't just have more colors though! compared to the CPC, a screen that can be split into sections, and each section can be a different screen mode and color pallete - this can be done with clever interrupts on the CPC, but the Enterprise does this in hardware, without interrupts or cpu power used - allowing for far more colorsplits, The color palette is also better - the regular CPC has 27 possible colors, but the Enterprise has 256

The Basic Enterprise has 64k, but we'll be focusing on the 256k version

Cpu 4 mhz Z80
Ram 64k / 128k
Resolution 320x200 4 color
160x200 16 color
80x200 256 color
Sound chip 3 Channel sound (non AY)

Some sites I think you need to check out for English language info on the Enterprise 128!
Learn Z80 With Vampires! - the Enterprise is being covered in my ongoing Z80 Assembly tutorials!
EP128emu - Enterprise Emulator - Set up guide
ep128.hu - great english enterprise 128 site
gafz enterprise forever site - another great english site
English Books for the EP128
Enterprise OS HTML documentation

The Enterprise screen memory location and layout is defined by a LPT block
Each Line contains 16 bytes in the format below:

Offset Name Bytes Example Meaning
0 SC 1 256-200 LLLLLLLL Two's complement of the number of scanlines in this mode line. Zero means 256 scanlines.
1 MB 1 %01010010 ICCRMMML I   VINT=0, no IRQ
CC  Colour Mode=01, 4 colours mode (2/4/16/256)
R   VRES=1, full vertical resolution (full/half)
MMM Video Mode=001, pixel graphics mode
L   Reload=0, LPT will continue
2 LM 1 11 SSLLLLL S    Special bits in 2 color mode
L    Left Margin
3 RM 1 51 SSRRRRR S    Special bits in 2 color mode
R    Right Margin
4 VIDADDR 2 &0000 LLLLLLL HHHHHHHH Memory address of Vram in first 64k of memory (low number banks - not 128k upgrade)
6 VIDADDR2 2 ? LLLLLLL HHHHHHHH Second Video Data address - not used in pixel graphics Modes
8 COL0-7 1x8 %00000111 g0  r0  b0  g1  r1  b1  g2  r2 8 palette definitions (8-15 are the same, with FIXBIAS offset)
16 SC - - - Next line in the LPT block 

Hello World

Here's my Hello World example. I couldn't find one, so I had to write it! It uses the operating system to access the screen and keyboard. This code was tested using WinApe - which is a CPC emulator, but it can compile ASM program code just fine
Download this from the sourcecode link at the top of this page!
write "..\RelEnt\program.com"

;            Hello World
;    Show a hello world message, then read a key
;    From the keyboard and show it.
;    Screen and keyboard ops use Enterprise OS calls
;    by opening 'stream' devices to the Keyboard and
;    screen

ORG &00F0
    DB 0,5               ;type 5 - Binary Program
    DW FileEnd-FileStart       ;File length
    DB 0,0,0,0,0,0,0,0,0,0,0,0 ;Spacer
; org &0100
    LD SP,&100    ;set the Stack to a safe place

    ld c,MODE_VID        ;Set text mode
    ld d,0
    call ENT_Writevar

    ld c,COLR_VID        ;Set 2 color
    ld d,0
    call ENT_Writevar

    ld c,X_SIZ_VID        ; 40 Chars Wide
    ld d,40
    call ENT_Writevar

    ld c,Y_SIZ_VID        ;24 chars tall
    ld d,24
    call ENT_Writevar

    ld de,ENT_Screenname     ;Open Screen as stream 10
    ld a,10
    call ENT_OpenStream    

    ;Display the just opened screen
    ld a,10    ; A channel number (1..255)
    ld b,1    ; B @@DISP (=1) (special function code)
    ld c,1    ; C 1st row in page to display (1..size)
    ld d,24  ; D number of rows to display (1..27)
    ld e,1  ; E row on screen where first row should appear (1..27)
    call ENT_SpecialFunc

    ld de,ENT_Keboardname    ; Open the keyboard as stream 11
    ld a,11
    call ENT_OpenStream
;            INIT Done
    ld hl,Message
    call PrintString    ;Print Hello world message

    call NewLine        

    call WaitChar        ;Wait for a keypress

    push af
        ld hl,Message2    ;Print 'You Pressed' message
        call PrintString
    pop af
    call PrintChar        ;print the char the user pressed
    call NewLine

    halt    ;stop execution - I've not figured out how to return to basic!

Message: db 'Hello World!',255
Message2: db 'Key Pressed:',255

    ld a,(hl)
    cp 255
    ret z
    inc hl
    call PrintChar
jr PrintString

;        Functions for controling EXOS

MODE_VID  equ 22    ;Enterprise OS variable numbers
COLR_VID  equ 23
X_SIZ_VID equ 24
Y_SIZ_VID equ 25    

    ;Open stream A from device string DE
    ;DE should point to a string like...  db 6,'VIDEO;'  or db 9,'KEYBOARD;' (replace ; with a colon)
    rst 6
    db 1     ;open stream
    push de
    push hl
    push bc
        ld a,11
        rst 6
        db 5     ;read from channel - result in b
        ld a,b
    pop bc
    pop hl
    pop de
    push de
    push hl
    push bc
        ld b,a
        ld a,10
        rst 6
        db 7     ;write to channel a
    pop bc
    pop hl
    pop de

    ld a,13
    call PrintChar
    ld a,10
    call PrintChar
ENT_readvar:        ;readvar C from enterprise OS
    ld b,0
    rst 6
    db 16

ENT_Writevar:        ;WriteVar C=D to Enterprise OS
    ld b,1
    rst 6
    db 16

ENT_SpecialFunc:    ;Special Function (for displaying screen)
    rst 6
    db 11
;Device names db [length],'name;'
ENT_Screenname: db 6,'VIDEO:'
ENT_Keboardname: db 9,'KEYBOARD:'

Starting the program:

The program will show hello world, then pause for a keypress

Ports on the Enterprise

Port Purpose Bits Bit Meaning
&80 Fixbias (Color 8-15 top bits) ----FFFFF
&81 Border Eight bit colour value which will be displayed outside the margins of all mode lines.
&82 LPL – Line Paramater Table Low Byte Low part (A4..A11) of the line parameter base pointer.
&83 LPH – Line Paramater Table High Byte High part of the line parameter base pointer.
&A0 Channel 0 Tone L LLLLLLLL L=Tone Low Byte… Lower values=Higher tone
&A1 Channel 0 Tone H RPCCHHHH H=Tone High Bits / polynomial Counter / Ring Modulator (CH2) / highPass Filter (CH1)
&A2 Channel 1 Tone L LLLL L=Tone Low Byte… Lower values=Higher tone
&A3 Channel 1 Tone H RPCCHHHH H=Tone High Bits / polynomial Counter / Ring Modulator (CHN) / highPass Filter (CH2)
&A4 Channel 2 Tone L LLLL L=Tone Low Byte… Lower values=Higher tone
&A5 Channel 2 Tone H RPCCHHHH H=Tone High Bits / polynomial Counter / Ring Modulator (CH0) / highPass Filter (CHN)
&A6 Noise Channel frequency RHLBCCNN Noise (0=31khz 1-3=Channel 0-2 link) / polynominal Counter/ swap Bits 7 & 17 of pc / Lowpass /Highpass / Ring modulator
&A7 Sync & Interrupt rate -IIDDSSS Interrupts (0=1khz,1=50hz,2=tone0,3=tone1) D=da ladder (speccy 48k emu) / Sync for tone 0,1,2 (1=hold 0=run)
&A8 Tone Channel 0 LH Amplitude --VVVVVV D/A ladder (tape port, Speaker)
&A9 Tone Channel 1 LH Amplitude --VVVVVV
&AA Tone Channel 2 LH Amplitude --VVVVVV
&AB Noise Channel LH Amplitude --VVVVVV
&AC Tone Channel 0 RH Amplitude --VVVVVV D/A ladder (Speaker R)
&AD Tone Channel 1 RH Amplitude --VVVVVV
&AE Tone Channel 2 RH Amplitude --VVVVVV
&AF Noise Channel RH Amplitude --VVVVVV
&B0 Ram page 0 (0000-4000)

&B1 Ram page 1 (4000-8000)

&B2 Ram page 2 (8000-C000)

&B3 Ram page 3 (C000-FFFF)

&B4 Interrupt latches

&B5 Select keyboard/joy row (out)

&B5 read keyboard row (in)

&B6 Read Joy row (in)

&B7 WR2 / RD2 (in/out)

&BF Ram options (out) (&0C = fast)

Enterprise Programming Tutorials:
P3 - Bitmap graphics on the Amstrad CPC and Enterprise 128
P7 - Keyreading on the MSX, Enterprise and TI-83
General Z80 Assembly Tutorials:
B. Beginner series - Learn the basics
A. Advanced series - In more detail
M. Multiplatform series - programming methods that work on all systems

Visit www.ChibiAkumas.com to get my games and their source code! | Support me on patreon