Enterprise Forever

:UK => Programming => Topic started by: ssr86 on 2014.June.08. 21:52:15

Title: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.08. 21:52:15
Hi, I wanted to try to play around with some programming on the Enterprise 128 computer (using an emulator)... I'm currently programming a bit for Amstrad CPC using WinApe emulator's built in assembler, but don't know any cross-dev tools that I could use for programming on an Enterpise...
Actually I never knew about the existence of Enterprise computers... I read some discussion about it on cpcwiki forum two days ago (about Star Sabre conversion) and wanted to check a few things with nick's flexible graphic capabilities... Unfortunately I don't know how to start... Please help... 

What tools are you using?
Title: Re: How to begin assembly on Enterprise
Post by: jltursan on 2014.June.08. 23:25:35
I suppose a good programmer's editor with Z80 syntax highlighting (ConTEXT) and a Z80 cross compiler (sjASM, pasmo) is a good starting point; but I'm also curious about Enterprise development: good documentation sources, code examples or even ready to use IDEs...
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.09. 15:49:45
Thank you.
Ok, I installed ConTEXT, downloaded pasmo, but how do I transfer the code into an emulator (and which of the two (?) should be better for this) to execute?

It seems that it's really hard to find info about programming the enterprise (other than the official tech documentation)...
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.09. 16:27:36
I using Programmer's Notepad (http://www.pnotepad.org/) for editing, and Sjasm 0.396 (http://home.online.nl/smastijn/sjasm39g6.zip) for compile.
Ep128emu built in debugger are very powerful with many options, and with LUA scripts you can done very advanced debugging.

In ep128emu if FileIO config loaded, then you can LOAD/SAVE files from your PC drive directly. Just select Work directory in the emulator menu, and put your Enterprise files to this directory.

For running your code need a loader program in a EXOS compatible file format, which are allocate memory, set up screen, etc
Once I uploaded one example there. (http://enterpriseforever.com/other-topics/xenon-2-on-enterprise/msg28248/#msg28248)

If you want to run existing CPC code, then needed in the loader program set up similar enviromement as the CPC. I think ask forum member: geco and IstvanV who are masters of converting CPC programs to Enterprise.
At source code level will be very easy.
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.June.09. 16:50:14
Welcome here :)
I suggest to you also what Zozo mentioned, if you need any help, or hint please do not hesitate.
If you want to test only small code, you can do it in 2 ways: The 1st is what mentioned by Zozo, and the sample is very good, it contains a lot of useful stuff. If you do not need any additional allocated memory, then you can create an EXOS 5 header program, it can be loaded directly to the Enterprise, these programs are loaded into 0100h, so you can set a breakpoint to 0100h and the debugger window will appear when the program is loaded.

Code: [Select]
        org 00f0h
db 00,05
dw fillen
db 00,00,00,00,00,00,00,00,00,00,00,00
startpr
         (code)

fillen   equ $-startpr

The 2nd:
you can load the code directly to EP128emu in debugger window PAGE2, by typing L "file name" 0 xxxx (load address) into top left box, if the code is loaded then with ;xxxx you can give an execution address. ( in this case be aware, if you did not change memory settings, then in most cases at Page 0 first memory segment of EP (in a normal EP128 setup it is 0F8h) ,page 1,2 mostly contains 0ffh segment, which is system segment, and page 3 mostly  contains ROM)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.09. 18:23:07
I managed to assemble the given sample.asm to com file using pasmo. Loaded it using the ep128emu. 
...I have a question...
Where does the video memory start? The pointer VIDCIM1 is equal to &0000... but I doubt that the vmem is at &0000, because I'd see some random pixels on screen. Changed the border color to see that 'something' is going on...
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.09. 19:04:26
VIDCIM1 are video (Nick) address of the video memory. It is deppend about which video segment allocated. In the standard configurations will be 0000h at Ep128 and 4000h at EP64.

For the Z80 access it is paged to Page 3 and can be accessed from C000h-... But you can page to any other page.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.09. 21:39:14
It seems that the Line Parameter Table can be max 256 bytes long... is there really such limitation? If so, then maybe it can be overcome someway (interrupts?)?...
I thought that I read that there can be "infinitely many" modelines... And also read that the enterprise can repeat display lines (VRES=0). I thought that it would be pretty straightforward to obtain a 160x128 16color and 80x64 256 color blocky resolutions (especially the first would be fun as a kind of "handheld console" resolution)... But if there's this limit on the size of LPT then it seems not so easy to do (impossible?). Can somebody help?
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.09. 21:53:07
The 256 bytes limit only in this example. No limit for LPT size, can be up to 64K :-) ok practically good idea left some video memory for the pixel data :-D
Most of EP programs use a separate video segment for the LPT table.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.10. 04:21:58
That's great! I should think and check more before I write here...
I'll try and finish the code once I get back from work then.

The same "double height pixels" mode (160x128x16) on the amstrad costs cpu time (drawing every line twice), no save of vmem, but saves memory for stored gfx (sprites, tiles, etc. take up half the memory). Or one can display a 160x128 screen but with a border line between every scanline of gfx screen... This saves both time and vmem memory...but doesn't look that good because of the blank lines.

And enterprise should (is) able to do the "real" 160x128x16 mode with a "simple" Line Parameter Table (but quite long one - 16 bytes for every line of the "new mode" + what's needed for vsync... so a bit above 2048 bytes I guess). Great!

And after "feeding" Nick with values from the LPT, that memory can be used for other stuff, right?
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2014.June.10. 09:27:27
Quote
And after "feeding" Nick with values from the LPT, that memory can be used for other stuff, right?

I guess you mean that you think LPT is read only once from the VRAM and then it's not used at all (from VRAM, I mean). That's not true, Nick always read LPBs of LPT at every first 8 slots of each scanline (I am not sure though what happens if an LPB is for multiple scanlines: is the LPB re-read anyway on each scanline, or not?). Nick does not have enough internal memory to store the LPT, it only stores a single LPB until the next one is read, as far as I know. So, for example in theory you can modify the already used LPT in the memory and of course Nick will use that even without new LPT address set (it's another question that it can be risky to do, Nick may read the one LPB of the LPT while you are modifying etc etc). So, I think the correct answer is: Nick is always fed with LPBs on every scanlines, you can't reuse that memory for something other (of course unless you set another LPT up, then the memory area of the old one is not used anymore).
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.10. 10:14:42
Quote from: ssr86
And after "feeding" Nick with values from the LPT, that memory can be used for other stuff, right?
No, Nick continously reading it. But you can page out, and page in other memory segment for the Z80 if your program need a lot of memory.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.13. 15:47:29
Sorry, it's a little offtopic, but I didn't want to create another topic...
It's about the "Converting Spectrum programs to run on the Enterprise" document. It seems that a few pages before the last one are missing...
True?
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.June.13. 16:26:44
Yes, it seems one, or more pages are missing, but the source code what Zozo linked (also used for converted speccy programs) to you is better than that what you could see on this document.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.13. 20:22:28
Quote
the source code what Zozo linked (also used for converted speccy programs) to you is better than that what you could see on this document.

You mean the "sample.asm"? Yes, it's better, but it's also harder to for me to understand (just a newbie), because of all the exos calls :oops:... 
I'm just looking through the available source codes.
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.13. 20:37:58
If you do not understand something do not hesitate to ask!


What do you think about rename your first topic as "EP assembly for beginers" or something? And can continue talking about sample.asm or any other questions about how to begin.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.14. 12:26:25
Quote
What do you think about rename your first topic as "EP assembly for beginers" or something? And can continue talking about sample.asm or any other questions about how to begin.
I think it'd be not a bad idea:).
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.14. 12:33:19
Done :-)
Title: Re: How to begin assembly on Enterprise
Post by: IstvanV on 2014.June.15. 11:18:01
Quote from: lgb
I am not sure though what happens if an LPB is for multiple scanlines: is the LPB re-read anyway on each scanline, or not?
It is re-read on every line.
Title: Re: How to begin assembly on Enterprise
Post by: gflorez on 2014.June.15. 12:01:11
What can happen if I do an OUT to a non-existent port?

I'm playing with the SERIAL driver(I've disassembled the driver)....and want to clone the READ CHARACTER call.

I need to maintain DTR (bit 1 on port 0xB7)  to the same value during all the call, but the stock subroutine has hand-shake, not needed to communicating with a Microsoft mouse....(I know, I know is a waste of time but this is only for my amusement....).

By the way, I have connected successfully the Microsoft serial mouse directly to the EP, only four cables needed, powering itself from the data lines. But the problem is, every time DTR changes, the mice sends an ASCII "M"(mouse, as opposed to "K" keyboard), that is mixed with the information the mouse was previously sending, resulting in some garbage....

Then it is required the same timing and I can't replace OUT (0xB7),A (11 clock cycles) with  three NOPs (12 clock cycles).

Can I replace it with, for example, OUT (0x00),A?
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.15. 15:22:44
1. How do I wait for the vertical retrace?
2. How can I turn off the OS? (or is it actually a bad idea?) The system calls complicate the code somewhat...and I have a feeling that the majority of games have it turned off (like the Amstrad's firmware on the CPC)...
3. Why in all (three) example codes I've seen, the interrupts are disabled somewhere at the beginning of the program and never turned on later in the code (implicitly).
 
And two not strictly-programming-related questions:
1. Where can I find a tracker (preferably a PC one...) for enterprise's sound chip?
2. Where can I find a palette reference for the enterprise? (I saw the formula for the colors in the docs and generated the palette to see, but maybe there's a table with possible gradients and stuff (maybe some example 16-color palettes to see how the bias system works visually, what constraints does it pose)?)
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.June.15. 16:37:57
Quote from: gflorez
What can happen if I do an OUT to a non-existent port?

Can I replace it with, for example, OUT (0x00),A?
I think nothing happens and you can do it, but if you substitute with CP (HL) and CP H it is also 2 bytes, and 11 clock cycles.
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.June.15. 16:48:05
Quote from: ssr86
1. How do I wait for the vertical retrace?
Put the interrupt request the previous LPB of Vertical retrace LPB, the interrupt will occure at retrace LPB.

Quote from: ssr86
2. How can I turn off the OS? (or is it actually a bad idea?) The system calls complicate the code somewhat...and I have a feeling that the majority of games have it turned off (like the Amstrad's firmware on the CPC)...
You do not need to turn off it, it is enough to page out it, and make an own interrupt routine, do not forget to set the right latch and divider bits of port 0b4h in the interrupt ,in case of video interrupt:
Code: [Select]
    ld   a,30h
    out  (0b4h),a
If it is not done, then the interrupt flag is not deleted, and the machine remains interrupt request loop.

Quote from: ssr86
3. Why in all (three) example codes I've seen, the interrupts are disabled somewhere at the beginning of the program and never turned on later in the code (implicitly).
I do not know, it is not necessary to turn off it, the stack pointer has to be set.
Quote from: ssr86
And two not strictly-programming-related questions:
1. Where can I find a tracker (preferably a PC one...) for enterprise's sound chip?
2. Where can I find a palette reference for the enterprise? (I saw the formula for the colors in the docs and generated the palette to see, but maybe there's a table with possible gradients and stuff (maybe some example 16-color palettes to see how the bias system works visually, what constraints does it pose)?)
Unfortunately there is no PC tracker, only tracker on EP.
I do not know if it exists, but I can do a palette only for bias values if it is good for you.
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2014.June.15. 21:59:32
Quote from: IstvanV
It is re-read on every line.

And are the possible changed values used? I mean an LPB can be valid for - let's say - 10 scanlines. What happens if I alter even the number of scanlines parmeter in the LPB and it's re-read by Nick on the next scanline. The other parameters (margins etc) are easier to imagine that will be used, but this made me thinking a bit. As far as I can imagine, that parameter won't cause any effect as number of scanlines for a given LPB should be a counter inside the Nick anyway.
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.15. 22:32:24
Quote from: ssr86
2. How can I turn off the OS? (or is it actually a bad idea?)
It is very bad idea write EXOS incompatible program!
Unfortunatelly no focus is placed about the right EXOS compatible programming at the start :cry: The Enterprise have really good, expandable operating system. (At the release time it is better than the MS-DOS!) Then many different configuration can be exist. At the start years exist a 64 and 128K, English and German machines, later these combined with EXDOS card.
And under the many years, many-many-many... RAM, ROM and other expansion created, Hard Disk system, and in current days SD Card systems.
In the expandable EXOS system many things are at variable address! Fix programing like as C64 or ZX Spectrum are bad idea on Enterprise!

With the bad programmed, EXOS incompatible programs (using fix address), found many-many problems under the years. For example running only on just English or just German machine, only with 128K, not running with memory expansion. Not running from floppy. Running from hard disk destroy Hard Disk extension RAM area and generate data loss, etc...

Many bad programs fixed, and continously fixing these. And at about the last ten years we care about all new programs are EXOS compatible then no new problem created :-)

From the practical side:
The most important things:
- don't use any memory what you not allocated from EXOS! EXOS 24 call the allocation. (http://gafz.enterpriseforever.com/Dokumentacio/Konyvek/EXOS_2.1_technikal_information/exos/kernel/Ch11.html#11.22)
- check errors (after memory allocation, or file operations) and if error use regular exit routine for step back to EXOS
- handle variable segment numbers, at general RAM only need store to paging table, with video segments also needed to calculate video address from the segment number
-specify warm start routine (restart program or exit)

All of these are included in the sample.asm! You need just write the main code! :-)

If you can specify which memory paging, and which video mode needed for you then I can modify the sample for your requirements!


If you will write game or demo you will use New Application Program (http://gafz.enterpriseforever.com/Dokumentacio/Konyvek/EXOS_2.1_technikal_information/exos/kernel/Ch10.html#10.6) type with header 05h.
It is loaded from 0100h...
Under the 0100h EXOS only use 0030h-005Bh area. Then 0000h-002Fh area can be used by the user programs, usualy for RST 00h-28h routines. 005Ch-00FFh also can be used, many programs use as stack under 0100h.

Generaly demos/games don't use EXOS during the running, use it only for file I/O, and memory allocation. EXOS IRQ routine can be replaced (placing jump to 38h) but it is needed to restored before EXOS calls used (for example load next level in the game), or exit program.
If you directly programing the HW then need to disable EXOS interrupts, or define your own IRQ routine and replace the EXOS IRQ.

So, generaly don't need switch of OS, just don't use it under the main program.
Title: Re: How to begin assembly on Enterprise
Post by: gflorez on 2014.June.15. 22:48:32
To Geco:

There are some Z80 instructions lasting 11 time cycles, the lenght is not so important as this is new code, but unfortunately all of them can affect the flags or capital registers inside some nested loops.

Also a 7 cycles instruction plus a NOP doesn`t suits.

I think I will try the inexistent port OUT instruction or try to change previously the value of register A....18 times.

Thanks..
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.June.16. 08:59:27
Quote from: gflorez
To Geco:

There are some Z80 instructions lasting 11 time cycles, the lenght is not so important as this is new code, but unfortunately all of them can affect the flags or capital registers inside some nested loops.

Also a 7 cycles instruction plus a NOP doesn`t suits.

I think I will try the inexistent port OUT instruction or try to change previously the value of register A....18 times.

Thanks..
I thought that the flag register is not important, it will be modified later :oops:
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.16. 15:48:32
Quote
All of these are included in the sample.asm! You need just write the main code! (http://enterpriseforever.com/Smileys/phpbb/ds_icon_smile.gif)
..and that's why it is harder for me to read it... But I guess I shouldn't worry too much about the setup part and just get to the main code...

Quote
If you can specify which memory paging, and which video mode needed for you then I can modify the sample for your requirements!
Thanks, but I actually managed to get those code samples I've written for those blocky modes to work within the sample.asm.

About ensuring exos compatibility... is this enough:
Quote
(...) don't use EXOS during the running, use it only for file I/O, and memory allocation. EXOS IRQ routine can be replaced (placing jump to 38h) but it is needed to restored before EXOS calls used (for example load next level in the game), or exit program.
As for replacing the interrupt handler... will this be enough (as a dummy interrupt)?:
Code: [Select]
;; set interrupt
ld a,&c3        ; c3 = jp opcode
ld hl,Interrupt
ld (&0038),a
ld (&0039),hl

;; ...
;; and later...
.Interrupt:
   di
   ld a,30h
   out (0b4h),a
   ei
   ret

I suppose it is a stupid question...but...
I set up the virq in my LPT and now...how do I check for this video interrupt at the beginning of my program's mainloop? 
I am looking for a equivalent of amstrad's:
Code: [Select]
.FrameFlyB
    ld b,&f5
.FFBLoop
    in a,(c)
    rra
    jr nc,FFBLoop
    ret

@geco
Quote
Unfortunately there is no PC tracker, only tracker on EP.
I "checked" what I could find (not much)... Which is the most user friendly?
"Music Box" has a lot of example tunes to load...but how do I do that in the emulator? I use the fileIO but I get an "drive A" error...
Quote
I do not know if it exists, but I can do a palette only for bias values if it is good for you.
Thank you, but I don't want to waste your time. I should be able to do that on my own.
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.June.16. 16:20:30
Quote from: ssr86
About ensuring exos compatibility... is this enough:As for replacing the interrupt handler... will this be enough (as a dummy interrupt)?:
Code: [Select]
;; set interrupt
ld a,&c3        ; c3 = jp opcode
ld hl,Interrupt
ld (&0038),a
ld (&0039),hl

;; ...
;; and later...
.Interrupt:
   di
   ld a,30h
   out (0b4h),a
   ei
   ret
Yes, and the DI inside the interrupt is not necessary.

Quote from: ssr86
I suppose it is a stupid question...but...
I set up the virq in my LPT and now...how do I check for this video interrupt at the beginning of my program's mainloop?
I am looking for a equivalent of amstrad's:
Code: [Select]
.FrameFlyB
    ld b,&f5
.FFBLoop
    in a,(c)
    rra
    jr nc,FFBLoop
    ret
You can do it with a simple HALT instruction if interrupt is not disabled or
Code: [Select]
chk50hz  in   a,(0b4h)
         bit  4,a
         jr   z,chk50hz
Quote from: ssr86
@gecoI "checked" what I could find (not much)... Which is the most user friendly?
"Music Box" has a lot of example tunes to load...but how do I do that in the emulator? I use the fileIO but I get an "drive A" error... Thank you, but I don't want to waste your time. I should be able to do that on my own.
Music box is the most user friendly, but if I remember well you are not able to use all effects ( may be I have wrong )
FileIO is a good setting, just tick in emulator menu in Configure ... the Enable Virtual file I/O.

It is not a big issue, every bias is started at at bias value*8 on the palette, so
Bias 0 : col00 - col07
Bias 1 : col08 - col0f
...
Bias 1f: colf8 - colff
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.June.16. 17:29:49
Quote
You can do it with a simple HALT instruction if interrupt is not disabled or
Oh, I thought that the z80 in interrupt mode 1 triggers six interrupts per frame.. :oops:(300Hz)...but that seems to be true only for the amstrad? Just read that on the spectrum
Quote
is triggered at the start of the vertical blank period of the screen refresh. This cannot be changed

And for the enterprise?
The only interrupt is virq, but can be triggered every second line of display?
Quote
You can do it with a simple HALT
...Actually the first thing I tried earlier was a halt...but then it didn't work...Commented some code and now it works...:oops:
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.June.16. 21:27:17
Yes the 300Hz on the CPC. On Enterprise 50Hz are the default, but if you need you can set more.
This is the Video IRQ generated by Nick. Dave also can generate interrupts, which are programable frq.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.September.30. 09:22:41
Is there a z80 crossassembler for use with Context that uses Maxam's assembler syntax (used by WinApe cpc emulator)?
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.September.30. 10:53:22
Quote from: ssr86
Is there a z80 crossassembler for use with Context that uses Maxam's assembler syntax (used by WinApe cpc emulator)?
I used WinApe assembler once or twice, and if I remember well with a small modification of source you can translate the code with SJASM.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.September.30. 12:57:45
The thing is I'm writing a cpc image to sprite converter using the winape's compatible assembler syntax (from what I read it's maxam) and I considerer adding support for enterprise sprites (it shouldn't be that much work....). But when coding for ep I'm using Context with pasmo and changing my code from winape to pasmo is sometimes quite time consuming... ...and for now I wouldn't want to do all the work with adding pasmo compatible assembler output to the converter...

How much would there be changes with sjasm? And is there a page that shows how to setup sjasm in Context (sorry that I'm asking before starting to look for myself but previously I couldn't find too much help for sjasm and stuck with pasmo)
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.September.30. 13:08:29
Sorry I mixed WinCPC's assembler with WinAPE's assembler, I do not know the differences between theese assemblers.
There is nothing special for setting up context for SJASM source code as I remember, you should download z80 highlight set for context, last year I started to use Notepad++
Here is the help of SJASM:
[attachurl=1]
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.September.30. 13:46:14
And here is a sample code for SJASM: Loader of Rick Dangerous by Istvánv. (http://enterpriseforever.com/konvertalas/cpc/?action=dlattach;attach=5788)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.September.30. 15:20:42
Well, sjasm sure looks more similar to winaape (than pasmo at least). But from what I've seen so far: '&' can't be used for hexadecimal (not really a problem), rept can't be used in macros (well...this can be somewhat a problem for me) and a few more)...But still less changes between sjasm and maxam than pasmo (macro syntax,'.' can't be used in labels etc.) ...
I wouldn't want to create too much work for myself with this "different assembler syntax" problem at the moment (I've been coding this for a year now and I've gotten tired of it but still want to finish it)) but because of how I've coded the converter it'd be a pain to make changes in that now...... 
So I think I'll give up with this asm syntax compatibility...and just leave it as is (maxam)

With setting up Context for sjasm I meant what do I write in the "environment options"/"execute keys" tab...

Thank you for your help (and sorry for stupid questions).
 
I'll see what I'll be able to make of it...
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.September.30. 16:38:26
PYZ80 (under Python) uses & sign for hexa you can check that also, I do not prefer it, because error handling is much worse than SJASM, in Sjasm you can use $ sign instead of &. Yes, I remember that I found source with REPT, and I could not substitute it in SJASM, it is a useful command.
Unfortunately I do not remember for that option in context, possibly I never used.
There is another possibility, you attach the source, and I will try to convert to Sjasm source.
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.September.30. 16:41:41
In the newest verion of Sjasm 0.42 I found REPEAT statement, please check it, I did not have time to take closer look.
SJASM help (http://home.online.nl/smastijn/sjasmman2.html)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.October.07. 18:21:39
I've implemented the enterprise modes in my program... For now I'm leaving everything in the Maxam assembler syntax, because It'd be too much work for the moment and I want to release the converter untill the end of this month and I'm left with a lot of debugging to do... But I hope it'll work after manualy converting the syntax (sorry)... It works for the cpc and I'm using screen line addresses lookup table for the getting the next line address which should be universal... But haven't tested it all yet... stuck with finding errors and trying to fix them (or just giving up on them)

I'm writing because I have a problem with LPT generation... Say I want to have L (1<=L<=288) lines high and C chars wide, vertically centered display - how to code the border and vblank lines so it will work properly?...
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.October.07. 20:15:40
Quote from: ssr86
I'm writing because I have a problem with LPT generation... Say I want to have L (1<=L<=288) lines high and C chars wide, vertically centered display - how to code the border and vblank lines so it will work properly?...
Do you want a separate LPT lines for each pixel lines, or a shortest LPT (then two lines needed for the max 288 lines, plus the sync block)?
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.October.08. 09:56:28
I have roblems with the sync block.
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2014.October.08. 10:17:35
Quote from: ssr86
I have roblems with the sync block.
As I remember, the sysnc block should be left untouched, you can put an LPB line before sync block, and there the number of lines can be varied as you want.
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2014.October.08. 10:21:10
Quote from: ssr86
I have roblems with the sync block.
My sync block from the IVIEW, can be used up to 301 lines screen.
Code: ZiLOG Z80 Assembler
  1. SYNC
  2. BOTTM       DEFB 105,12H,63,0,0,0,0,0,0,0,0,0,0,0,0,0
  3.                                ;151 lines, size of the bottom border
  4.  
  5.             DEFB 252,16,6,63,0,0,0,0,0,0,0,0,0,0,0,0
  6.                                ;4 lines, sync on
  7.  
  8.             DEFB 255,90H,63,32,0,0,0,0,0,0,0,0,0,0,0,0
  9.                                ;1 line, sync switch of at half line
  10.                                ;Nick generate IRQ here
  11.  
  12.             DEFB 252,12H,6,63,0,0,0,0,0,0,0,0,0,0,0,0
  13.                                ;4 empty lines (VBLANK)
  14.  
  15. TOPM        DEFB 104,13H,63,0,0,0,0,0,0,0,0,0,0,0,0,0
  16.                                ;152 lines, size of top border
  17.  
  18. SYNCH       EQU $-SYNC ;size of sync block

At default this block contain the whole screen, displaying 303 (152+151) lines of border.
You define your lines before this block. Divide the number of your lines, and add one half+remaining to the (TOPM), another half to (BOTTM). This reduce the top and bottom border section.

For example you want to display 200 lines, then add 100 to (TOPM) it is will be 204, another 100 to (BOTTM) it is will be 205.
For a 201 lines, add 101 to (TOPM)=205, add 100 to (BOTTM)=205.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.October.08. 12:39:22
Oh, thank you very much. Previously I just changed the values for the number of border lines in the code found in the sample for setting the lpt, but without understanding what and why in the sync part.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2014.October.08. 16:38:57
What is the role of left/right margin in the sync lines? Because I looked at the few examples I gathered and there are other values written...
I mean the example found in one of the exos manuals:
Code: [Select]
; PIXEL for 256 lines (4 color)
DB    256-256,pixel+c4+vres,14,14+32
DW    screen,0
DB    0,1,2,3,4,5,6,7

;blank for 5 lines               ; bottom margin
DB    256-5,lpixel,63,0
DB    0,0,0,0,0,0,0,0,0,0,0,0

;black for 10 lines              ; start of vertical blanking period
DB    256-10,lpixel,4,63
DB    0,0,0,0,0,0,0,0,0,0,0,0

;start vsync (4 lines)           ; vertical sync pulse
DB    256-4,vblank,4,63
DB    0,0,0,0,0,0,0,0,0,0,0,0

;end vsync (1 line)              ; finish vertical sync pulse
DB    256-1,vblank,63,4
DB    0,0,0,0,0,0,0,0,0,0,0,0

;black for 30 lines
DB    256-30,lpixel,4,63         ; rest of vertical blanking period
DB    0,0,0,0,0,0,0,0,0,0,0,0

;blank for 6 lines               ; top margin with reload to satart again
DB    256-6,reload+lpixel,63,0
DB    0,0,0,0,0,0,0,0,0,0,0,0
Title: Re: How to begin assembly on Enterprise
Post by: IstvanV on 2014.October.08. 17:25:41
Quote from: ssr86
What is the role of left/right margin in the sync lines?
It determines where the VSYNC begins and ends within a line. When the video mode for a line is 0, then borders are blank (always black, regardless of the border color), and the active area is VSYNC (negative level relative to black). Without interlace, it should start at the beginning of a line, and the standard length is 2.5 lines, although it is not a problem if it is slightly longer. There are normally 3 blank lines before the VSYNC, and also a few after it. The additional black lines in the EXOS manual are the rest of the vertical retrace period, this area is also what TV broadcast uses for teletext.

For comparison, Commodore machines use 3 vblank + 3 vsync + 3 vblank + 9 additional black lines (18 total).

In the case of the NICK chip, a VBLANK line (mode 0 and all border) is slightly different from a normal fully black line, as it does not output the burst signal before the visible area of the line.

For centering the picture on the screen, it may be useful to know that the horizontal center position for the margins is 31 in theory (and on ep128emu), but on a real machine with a TV this is typically slightly to the left (by up to a whole character), so when the number of columns is odd, it is best to round the margins (31 +/- width/2) up, rather than down. On the emulator, 288 lines are displayed out of 312 total, and the bottom of the visible area is aligned so that it ends 3 lines (i.e. the same as the recommended number of initial blank lines) before VSYNC. On a real TV, it is normally centered similarly (maybe moved up slightly by 1-2 lines), but with at least a few percents of overscan, so fewer lines are visible.

In the LPBs where a margin is 63, it means that the margin is never reached. NICK counts the character position within a line from 0 to 56, and when it is equal to the left or right margin, the display becomes active or border colored, respectively, otherwise its state does not change. Changing a margin from or to 0 at the beginning of an LPB may be missed for one line, because the margin values are read later from the LPB than position 0.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.May.17. 15:53:43
Until now I have loaded all my code with the ep128emu debugger and had to do it twice for my programs to run. I'm assembling to com files with the "new application program" header type (?). Because of the memory layout I use, my code is scattered over more than 47kb of memory. I can't load the com files from basic. My code is not exos compatible.:oops: 
How should I load my programs?
Should I have the com file just be a loader for the "real" code? (I think most games have a small com and at least one prg file...)
Could someone explain how this should be done properly?:oops:
 
Title: Re: How to begin assembly on Enterprise
Post by: IstvanV on 2015.May.17. 18:46:39
Should I have the com file just be a loader for the "real" code? (I think most games have a small com and at least one prg file...)
Could someone explain how this should be done properly?:oops:

Yes, using a small .com file and a large .prg file is a common solution.

Alternatively, if not using multiple files is important, you can increase the size of the .com file up to about 63 KB, and then use epcompress (http://enterpriseforever.com/programozas/fajltomorites-enterprise-on/msg31929/#msg31929) to reduce it to the standard maximum of 47.75 KB or below so that EXOS can load it. The -m3 algorithm is the least efficient compression, but it should be good enough for this purpose, and it is the fastest to unpack and has the lowest memory usage, so it leaves the most space for the program.

Another, more complicated single file solution is to append an EXOS end of file header and then the contents of the .prg at the end of the .com file, and then the loader should open the file again, skip the initial (.com + EOF) part of the file, and load the .prg data that can be of any size. However, this does not work well on tape (the user would have to rewind), and renaming the file would break the loader.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.May.17. 19:17:12
Yes, using a small .com file and a large .prg file is a common solution.
How do I write a loader?:oops:

Alternatively, if not using multiple files is important, you can increase the size of the .com file up to about 63 KB, and then use epcompress (http://enterpriseforever.com/programozas/fajltomorites-enterprise-on/msg31929/#msg31929) to reduce it to the standard maximum of 47.75 KB or below so that EXOS can load it. The -m3 algorithm is the least efficient compression, but it should be good enough for this purpose, and it is the fastest to unpack and has the lowest memory usage, so it leaves the most space for the program.

For instance, the margin examples I've posted a while back. They have code in $0100-$0800, but the screens start at $8000 and $c000, then the LPT is placed in $f000-$f94f, so it won't run from basic (and in through debugger I have to initially load it twice to the memory). If I wanted to keep this layout I would have to compress the gfx, keep the lpt in another place in memory and later unpack the gfx and copy the lpt where I wanted it to be, right (or just skip compression and just copy the data from lower memory to where I want...)?:oops:
 
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.May.18. 09:18:01
How do I write a loader?:oops:
Here is a small loader example:
Code: [Select]
       macro exos n
                rst   030h
                defb  n
        endm

        org     00f0h
        db    00,05
        dw    fillen
        db    00,00,00,00,00,00,00,00,00,00,00,00

startpr ld     sp,0100h
        ld      a,0ffh
        out     (0b2h),a ;system segment to page2
        ld      hl,error
        ld      (0bff8h),hl ;store soft reset in EXOS segment

        call    seg                 ;ask a free segment from EXOS
        out     (0b3h),a
        xor     a ;open channel 0, and load file header of prg
        ld      de,prg  
        exos    1  
        jp      nz,error ;jp error if error occured

        ld      de,0c000h                ;load file to 0c000h, length 4000h
        ld      bc,4000h
        exos    6
        jp      nz,error ;jp error if error occured

        xor     a
        exos    3 ;close channel 0

        jp      prgstart

prg    db    8,"data.prg"               ;length of file name, file name

seg     exos 24 ;ask a free 16k page
        jp nz,error ;if not enough memory, then reset
        ld a,c
        ret

error   di ;soft reset routin
        ld      sp,0100h
        ld      a,0ffh
        out     (0b2h),a
        ld      c,40h
        exos    0
        ld      a,01h
        out     (0b3h), a
        ld      a,06h
        jp      0c00dh

fillen  equ $-startpr
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.May.18. 10:04:46
Code: [Select]
jp      nz,error ;jp hiba if error occuredHungarian label left in the comment :oops:
And it is also recommended after the EXOS 6.
Title: Re: How to begin assembly on Enterprise
Post by: IstvanV on 2015.May.18. 10:29:42
How do I write a loader?:oops:
 
For instance, the margin examples I've posted a while back. They have code in $0100-$0800, but the screens start at $8000 and $c000, then the LPT is placed in $f000-$f94f, so it won't run from basic (and in through debugger I have to initially load it twice to the memory). If I wanted to keep this layout I would have to compress the gfx, keep the lpt in another place in memory and later unpack the gfx and copy the lpt where I wanted it to be, right (or just skip compression and just copy the data from lower memory to where I want...)?:oops:

With compression, you can basically create a self-extracting .com (EXOS 5) file that uses all space from 100h to FFFFh (with the epcompress -m3 method, where all the decompressor code and data is below 100h), as long as the compressed size is valid (<= 47.75 kilobytes) for the EXOS loader. Large unused memory areas that are filled with zeros are compressed to only a few bytes. After the original program is unpacked in memory, it is run as usual starting at 100h.

For larger (> 63.75 KB) or more complex programs, it is best to use a loader and separate .prg file.
Title: Re: How to begin assembly on Enterprise
Post by: IstvanV on 2015.May.18. 10:33:28
Hungarian label left in the comment :oops:

Also, the 'szeg' label has not been renamed to 'seg' where the routine is called.
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2015.May.18. 10:39:38
Large unused memory areas that are filled with zeros are compressed to only a few bytes. After the original program is unpacked in memory, it is run as usual starting at 100h.

At the other hand, I always felt, that a decent assembler/linker should provide the BSS area, thus uninitialized data. I am not sure eg sjasm can do this, I usually "allocate" these kind of data with my own macros after the end of the loaded program, and if needed, I fill that area with zeroes at the beginning of the program (so having zero for the value of these locations). I only say this, because I saw many software contain "BSS like" parts at the middle of the program, thus wasting space on the stored program file at least. Okey, with compression is more or less not an issue too much, I think :)
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.May.18. 10:50:06
When you load games from tape you can hear when loading lot of zeros. I really hate when I hear it for a minutes... :twisted: Ok, from SD card don't problem, just wasting of the storage space :-)
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.May.18. 10:50:33
Also, the 'szeg' label has not been renamed to 'seg' where the routine is called.

Mistakes have been corrected. This CALL SZEG mistake is interesting, because I typed it after I renamed the label :D
Title: Re: How to begin assembly on Enterprise
Post by: Tuby128 on 2015.May.18. 12:25:43
When you load games from tape you can hear when loading lot of zeros. I really hate when I hear it for a minutes... :twisted: Ok, from SD card don't problem, just wasting of the storage space :-)
Can you show me how it's sounds when a lot of zeros loaded from tape?
Title: Re: How to begin assembly on Enterprise
Post by: IstvanV on 2015.May.18. 13:46:06
Can you show me how it's sounds when a lot of zeros loaded from tape?

A long sequence of zero bytes is a square wave at about 2000 Hz. With FFh bytes instead, it is 3000 Hz. In other words, empty space filled with FFh loads faster from tape than zeros. But it does not matter with compression. In general, anything that sounds like a pure, continuous tone on tape is likely to be a sequence of identical bytes.
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.May.18. 14:14:22
And the CRC bytes add some rhythm :-)
Title: Re: How to begin assembly on Enterprise
Post by: Prodatron on 2015.May.18. 17:22:54
And the CRC bytes add some rhythm :-)
:lol: :lol: :lol:

Is there a z80 crossassembler for use with Context that uses Maxam's assembler syntax (used by WinApe cpc emulator)?

Not sure how you already solved this problem.
You can use WinApe to assemble to a file on your PC, then transfer this file to a disc image and load/use it in Ep128Emu. This is the way I am developing for the Enterprise and all other Z80 machines, so I always have the same assembler (WinApe, =Maxam syntax) for all platforms.
Just use the WRITE command at the beginning of your source code:

Code: [Select]
WRITE "C:\Z80coding\PROGRAM.COM"

...or whatever :) I only load a small "make"-file in the Assembler-Editor of WinApe which is loading the full sourcecode. The most simple "make.asm" would look like this:

Code: [Select]
WRITE "C:\Z80coding\PROGRAM.COM"
READ "C:\Z80coding\PROGRAM.ASM"

I like the Alt+H shortcut in Ep128Emu a lot for reloading the disc image in drive A. This is very helpful and missing in other emulators.
Title: Re: How to begin assembly on Enterprise
Post by: Tuby128 on 2015.May.18. 18:17:26
... In other words, empty space filled with FFh loads faster from tape than zeros....
This cannot be true. The bit time-slots of the Manchaster code is equidistant. And thus no matter what kind of bits coded inside two same-lenght file it's always has the same time lenght.

HU:
Ez nem lehet igaz. A Manchester-code idő szeletei időben azonos szélességűek. Így teljesen mindegy milyen bitek vannak két azonos hosszúságú fájlban, időben ugyanolyan hosszúak.
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.May.18. 18:31:16
But who talk about Manchaster code here? We talking about the EXOS tape format.
There is 48K 00h: 4:14
And 48K FFh: 3:02
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.May.18. 18:36:09
EXOS tape format: (http://gafz.enterpriseforever.com/Dokumentacio/Konyvek/EXOS_2.1_technikal_information/exos/cassette/Ch6.html)
Code: [Select]
The actual whole cycle times and frequencies used for the two tape speeds are:

                   Fast Speed        Slow Speed

    leader cycle   424µs (2358 Hz)   1000µs (1000 Hz)
    one bit        344µs (2907 Hz)    800µs (1250 Hz)
    zero bit       504µs (1984 Hz)   1200µs ( 883 Hz)
    sync bit       696µs (1437 Hz)   1600µs ( 625 Hz)
Title: Re: How to begin assembly on Enterprise
Post by: Tuby128 on 2015.May.18. 18:42:07
Yes, you are completly right. I am comming from an another planet.
 I cannot belive that. I had thought till now, that the Enterprise uses Mancester code for tape.
 I learn every day new things.
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.May.18. 19:10:08
There is 48K 00h: 4:14
And 48K FFh: 3:02
It was interesting to hear the samples :)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.June.06. 17:18:54
Can't get my file to load using Geco's example...
I get error after calling exos 1.
I don't really know how my prg file should look as I can't find any info.
I've tried without a header, with a type 5 header and header copied from rick2 prg.

What am I doing wrong?

(sorry - I don't really know what I am doing...)
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.June.07. 12:00:43
I get error after calling exos 1.
What is the error code?

Which configuration used for loading?

Quote
I've tried without a header, with a type 5 header and header copied from rick2 prg.
Header don't needed for the data file.

Are you edited the file name and length in the loader for your program?
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.June.07. 13:56:40
What is the error code?
A=$fe (I get "EXOS function call not allowed" - after calling exos 28 which supposedly translates the error number to message string)
Quote
Which configuration used for loading?
You mean ep128emu configuration? ep128-exdos-fileio...
The file is in the same directory as the com file.
I'm using pasmo.
Quote
Header don't needed for the data file.
ok
Quote
Are you edited the file name and length in the loader for your program?
I had my prg test file named as in the example code - "data.prg".
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.June.07. 20:26:08
A=$fe (I get "EXOS function call not allowed" - after calling exos 28 which supposedly translates the error number to message string)
:shock:
Can you upload your program for can I see it in debugger?
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.June.07. 21:56:38
:shock:
Can you upload your program for can I see it in debugger?
Well I just copy-pasted the example code into my assembler, prepared a small prg-to-be file with little code without start address.
Compiled the prg with --bin option of the pasmo assembler.
Loading the com file through the ep128emu debugger.

I'm pretty sure that it's me doing some stupid error...
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.June.07. 22:16:42
EXOS 1 working for me without error :oops:
- I putted the files to one directory.
- loaded one fileio config for the ep128emu
- select the directory as work directory for the emulator (ALT+F)
- optionaly at the debugger set breakpoint to 0100x (=execute at 0100h)
- at the BASIC prompt press START (F1) for load the program, then select the .COM file

At the EXOS 6 need to put real length of the file for avoid the End of file error. (Or temporary remove the JP NZ in the testing phase, just put back at the final version.)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.June.08. 19:22:17
- at the BASIC prompt press START (F1) for load the program, then select the .COM file

I've been loading the com file from debugger and that was the problem. When loading from basic it works (after applying the corrections for exos 6 to work).

Should've at least tried that before posting...
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.August.14. 12:43:13
I've got another question...

I'm struggling to write a loader for the game resources (it's been some time since I last touched it)
My problem is segment $ff. It seems that the system segment has to always be assigned to a page in memory. I can't allocate it (or don't know how) so I can't load from a file to it (or so it seems). I could load the data into another segment and later copy (or decrunch) it into the $ff segment. But I would like to know how it should be done the right way.

I would like to have 2 video segments and 2 non-video faster segments at every time. Seems I can't leave out the system segment so the second video would have to be $ff...
Or am I just doing something wrong?:oops:
Title: Re: How to begin assembly on Enterprise
Post by: Zozosoft on 2015.August.14. 13:03:13
It seems that the system segment has to always be assigned to a page in memory.
Only under the system operations. In your program can you page in anything to Page1-3. (on P0 normaly are the Page 0 segment, where the EXOS entry point and IRQ handler at the start.)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.August.14. 16:18:08
Only under the system operations. In your program can you page in anything to Page1-3. (on P0 normaly are the Page 0 segment, where the EXOS entry point and IRQ handler at the start.)

So in order to make use of the $ff segment with exos calls (for loading from file) I have to load all data to another segment and later move it to the $ff segment, right?
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2015.August.14. 16:40:39
So in order to make use of the $ff segment with exos calls (for loading from file) I have to load all data to another segment and later move it to the $ff segment, right?

You wrote, you need 2 video segments. Then you should not use segment $FF but some other, so you won't have these problems (there is 64K video RAM so there are four 16K sized video segments: $FC, $FD, $FE, $FF). $FF is the system segment, so if you overwrite it, you probably won't be able to use any EXOS function, no keyboard handling (by EXOS) etc whatsoever, also warm reset won't work, etc. The best way: use EXOS segment allocation call, thus you can be sure a segment is "yours". Unfortunately there is no EXOS call to allocate a _video_ segment. Common technique is to allocate segments (and remember them!) in a loop till you got enough video segments (segnum >= $FC) then free segments you don't need from the stored allocated ones created throughout the allocator loop.

Of course it's possible to "take over" the machine and use memory as you want, but then you may need to forget EXOS and you need to do everything at your own (direct hardware access). It can be painful if you need file access later too (especially because doing hardware level EXDOS card access won't work if the user has some other solution - like the SD card cartridge - where compatibility is provided at software level). But if you can pre-load anything before the "take over" it can be OK. Though on EP the "elegant" way that you don't need to "cold reset" the machine, the RAM disk is not cleared, etc, but it requires to keep system segment intact ...
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.August.14. 20:28:54
You wrote, you need 2 video segments. Then you should not use segment $FF but some other, so you won't have these problems (there is 64K video RAM so there are four 16K sized video segments: $FC, $FD, $FE, $FF). $FF is the system segment, so if you overwrite it, you probably won't be able to use any EXOS function, no keyboard handling (by EXOS) etc whatsoever, also warm reset won't work, etc.
But it seems that the system segment must always be mapped... And so I can't really use any other video segment then...
When I don't map $ff then my screen doesn't render - seems that there're some problems with LPT processing...
Is it normal, or am I just doing something wrong?
Quote
The best way: use EXOS segment allocation call, thus you can be sure a segment is "yours". Unfortunately there is no EXOS call to allocate a _video_ segment. Common technique is to allocate segments (and remember them!) in a loop till you got enough video segments (segnum >= $FC) then free segments you don't need from the stored allocated ones created throughout the allocator loop.
I'm actually doing something similar as I'm "basing" my code on geco's rick dangerous 2 loader.
Quote
Of course it's possible to "take over" the machine and use memory as you want, but then you may need to forget EXOS and you need to do everything at your own (direct hardware access). It can be painful if you need file access later too (especially because doing hardware level EXDOS card access won't work if the user has some other solution - like the SD card cartridge - where compatibility is provided at software level). But if you can pre-load anything before the "take over" it can be OK. Though on EP the "elegant" way that you don't need to "cold reset" the machine, the RAM disk is not cleared, etc, but it requires to keep system segment intact ...
I think I'd prefer to do it the "elegant" way...
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2015.August.14. 20:40:03
But it seems that the system segment must always be mapped... And so I can't really use any other video segment then...

First of all, you have four Z80 pages to map any segment of the 256 to. Second: you don't need system segment always mapped in. If you call an EXOS function or IRQ is serviced, it will be mapped in, and on return, your original mapping is restored. What you "should" always paged in is P0 (zero page segment from 0-3FFF) because eg the "head" of the IRQ routine is there. If you disable interrupts and you don't need to call EXOS functions for a while you don't even need P0 paged in. System segment is needed by EXOS, so if your code runs nobody is interested if system segment is mapped in or not. What I meant, that you should not overwrite system segment. If's another question that you can map some other segment with writing port $B3 and you can write there of course, since in memory it won't be written into the system segment ($FF) of course.


Quote
When I don't map $ff then my screen doesn't render - seems that there're some problems with LPT processing...

No! Important rule: the Z80 as the CPU sees memory "through" the Dave memory segment mapper (ports B0-B3 to set). But Nick *always* see the video RAM (segments $FC-$FF) regardless what you map in for the CPU. So the address Nick address 0 (eg for LD1 pointer in some LPB) *always* means the 0th byte in segment $FC even if that segment is not mapped in for the CPU at all! In other words: Nick uses another memory layout scheme, and sees 64K at the end of the EP memory space (thus segments $FC-$FF) linearly and always. The segment mapping is for the CPU _only_!
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.August.14. 20:57:42
No! Important rule: the Z80 as the CPU sees memory "through" the Dave memory segment mapper (ports B0-B3 to set). But Nick *always* see the video RAM (segments $FC-$FF) regardless what you map in for the CPU. So the address Nick address 0 (eg for LD1 pointer in some LPB) *always* means the 0th byte in segment $FC even if that segment is not mapped in for the CPU at all! In other words: Nick uses another memory layout scheme, and sees 64K at the end of the EP memory space (thus segments $FC-$FF) linearly and always. The segment mapping is for the CPU _only_!

Thanks! That was my problem - I set the lpt pointer with the address as in my mapped memory instead of the "absolute" nick memory address...
Sorry for being stupid...
(I'm happy I asked because I wouldn't have found the cause by myself)
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.August.15. 03:48:23
Sorry, it's me again...
How should "allocate segment and load data from a file into it" go?
If I use a segment allocation routine with exos 24 then I can't do exos 1 because I get insufficient memory.
All works when I don't do the allocation.
Using exos 25 for freeing the segments I won't need doesn't help.
I'm quite frustrated.
As you can see I don't really have a clue what I'm doing...
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.August.15. 10:59:07
Sorry, it's me again...
How should "allocate segment and load data from a file into it" go?
If I use a segment allocation routine with exos 24 then I can't do exos 1 because I get insufficient memory.
All works when I don't do the allocation.
Using exos 25 for freeing the segments I won't need doesn't help.
I'm quite frustrated.
As you can see I don't really have a clue what I'm doing...
If you use the video RAM request code from the loader then only 1 problem can be there, it saves the allocated segments into a place specified by HL, possibly this area is overwritten, and therefore EXOS 25 will not free up any page, so all of your segments remained in use therefore no free space for EXOS for loading.
Video RAM allocation is working in the following way:
Ask a free segment and store it at position HL, checks if it is not smaller than FC segment, if it is smaller then ask a new one until it reach FC-FF range, if you got FF the return code will be 7Fh it shows that you tried to allocate the system segment, and FF segment is also reserved by you, so if you try to load now something it will fail with insufficient memory, this is the reason why if you got the video RAM the allocated pages will be freed up by EXOS 25 calls it reads the pages from stored HL address.
Loader of Rick Dangerous is Istvanv's loader :), mine loaders are not so documented :)
If you upload the loader, we can help you easier :)
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2015.August.15. 11:31:42
Sorry, it's me again...
How should "allocate segment and load data from a file into it" go?
If I use a segment allocation routine with exos 24 then I can't do exos 1 because I get insufficient memory.
All works when I don't do the allocation.
Using exos 25 for freeing the segments I won't need doesn't help.
I'm quite frustrated.
As you can see I don't really have a clue what I'm doing...

It means you allocated all of the memory, so EXOS does not enough RAM for the data structure needed for the new channel to be open. What I've already told: if you need video segment you need to allocate all of the RAM (within a loop) and wait for having a video segment allocated (segnum >= $FC). However the problem here that you allocated segments then you don't really need, just to wait for a suitable (in our case: video-) segment. Thus, after getting the right segment you need to free the unneeded allocated segments. That is, in the loop, you need to store allocated segment numbers, and after you got a video segment you need that stored segment numbers to be used in the free segment EXOS call (excluding the segment you really need! of course). If you need just a "regular" segment, of course a single segment allocation EXOS call is enough, no need for loop, etc. Another thing: if you don't have any "whole segment" free, the segment allocation EXOS call return with "shared segment". That is, eg system segment is "splitted" (named as "EXOS boundary") and returned to the caller, but then you can only use a part of it, as the other part (above the EXOS boundary value) is used as the system segment. However, in this case, the system segment cannot be grown (towards the lower addresses) thus EXOS functions needs more system segment area will fail.

http://ep.homeserver.hu/Dokumentacio/Konyvek/EXOS_2.1_technikal_information/exos/kernel/Ch11.html

See here, EXOS function 24 description.

Also please note that page 0 (0-3FFF) is always allocated, if your program needs 16K of memory you don't need to do extra stuff. If your program to be loaded is longer than 16K, also you have an already allocated segment for page 1 (4000-7FFF) otherwise the program cannot be loaded at all, of course.

Quote
Thanks! That was my problem - I set the lpt pointer with the address as in my mapped memory instead of the "absolute" nick memory address...
Sorry for being stupid...

You shouldn't feel bad. The "problem" with EP128/EXOS that is has got quite "advanced" operating system compared to most of the other 8 bit computers. At least for me it felt quite "complicated" at first, and I also needed time to get to use to it, also some time is needed to understand its "philosophy", and for first it can be really felt as being "too complex" even for a minimal program like print something on the screen (eg open video page, whatever), compared to other 8 bit systems. But EXOS/etc is also the bright side of EP128, that it really have an unique software with quite "modern" (well, compared to its age) behaviour and features.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.August.15. 15:14:16
The loader looks like this:
Code: [Select]
loader:

        ld      a,0ffh
        out     (0b2h),a
        ld      hl,resetRoutine
        ld      (0bff8h),hl

        call    allocateMemory

ld c,$ff ; free system segment
exos 25  ;

call load_screen1_segment_data
call load_screen2_segment_data

ret


load_screen1_segment_data:

        ld a,(screen1_segment)
        out ($b3),a

        xor     a
        ld      de,dat1prg
        exos    1
         jp      nz,resetRoutine


        ld      de,0c000h
        ld      bc,9803
        exos    6

        jp      nz,resetRoutine

        xor     a
        exos    3

        ret

load_screen2_segment_data:

        ld a,(screen2_segment)
        out ($b3),a
        xor     a
        ld      de,dat1prg
        exos    1
        jp      nz,resetRoutine

        ld      de,0c000h
        ld      bc,14672
        exos    6
        jp      nz,resetRoutine

        xor     a
        exos    3

        ret


dat0prg    db    8,"dat0.prg"
dat1prg    db    8,"dat1.prg"

resetRoutine
        di ;soft reset routine
        ld      sp,0100h
        ld      a,0ffh
        out     (0b2h),a
        ld      c,40h
        exos    0
        ld      a,01h
        out     (0b3h), a
        ld      a,06h
        jp      0c00dh

allocateMemory
              ld de,segment_table+1
              ld hl,segment_table
              ld (hl),0
              ld bc,8
              ldir

ei
              ld hl,segment_table

am1
              exos 24   

              add a,a
              jr nz,am2

              ld (hl),c   
              inc l

              jr nz,am1   

am2:
;-----------------------
; for 1st video buffer (in-game)
call getVideoSegment
jr nc,resetRoutine
ld (screen1_segment),a

; get 2nd video buffer segment (in-game)
call getVideoSegment
jr nc,resetRoutine
ld (screen2_segment),a

; get additional video buffer segment
call getVideoSegment
jr nc,resetRoutine
ld (additional_video_segment),a

;----

; free unused segments:
ld hl,segment_table
am111:
call free_segment
inc l
jr nz,am111
ret
free_segment
xor a
cp (hl)
ret z
ld c,(hl)
ld (hl),a
exos 25
ret

getVideoSegment:
; numer segmentu zwracany w A
                ld a,$fb
                ld hl,segment_table
gvs1:
                cp (hl)
                jr c,gvs2
                inc l
                jp nz,gvs1
                ret
gvs2:
                ld a,(hl)
                ld (hl),0
                ret

screen1_segment equ $7fe0
screen2_segment equ $7fe1
additional_video_segment equ $7fe2

additional_normal_segment equ $7fe3


sharesegment_sizes equ $7fe0
sharesegment_table equ $7ff0
segment_table equ $7ff0+8

Quote
If you use the video RAM request code from the loader then only 1 problem can be there, it saves the allocated segments into a place specified by HL, possibly this area is overwritten, and therefore EXOS 25 will not free up any page, so all of your segments remained in use therefore no free space for EXOS for loading.
I checked and it isn't overwriting the segment_table area and really tries to free the unused segments (returns result 0 for each exos 25). But I had to free $ff to get no memory errors when opening channel and loading... Although I freed $fa and $fb earlier... But it's only a workaround...

Quote
Loader of Rick Dangerous is Istvanv's loader :), mine loaders are not so documented :)
Sorry Istvan
Title: Re: How to begin assembly on Enterprise
Post by: lgb on 2015.August.15. 17:34:50
I checked and it isn't overwriting the segment_table area and really tries to free the unused segments (returns result 0 for each exos 25). But I had to free $ff to get no memory errors when opening channel and loading... Although I freed $fa and $fb earlier... But it's only a workaround...

Well, I guess the problem here that you allocate all the segments in the system throughout your loop, in this situation the next allocate segment will not fail but provides the so called shared segment, the system segment itself, "split" at an address (this is called the EXOS boundary) between the system (ie EXOS) and you. The segment allocation EXOS call (function 24) can result in three "type of outcome":

1. If there is at least one free segment, it will be allocated for you, segment number is returned, status of the call is OK

2. If there is no free segment left, but shared segment is not allocated yet, then the call itself will return with status "error" as "SHARE" (can't remember the exact code for this in register A now), but actually it's not an error like other kind of error, but only a fact, that no "whole" free segment in the system remain so the system segment is provided for the user with the EXOS boundary in DE showing the address where it is split (so above that address within the segment should not be written otherwise your overwrite EXOS areas ...). However if you exploit this, system segment can't "grow" (downwards) anymore, thus functions need more memory by EXOS will fail (like maybe the open channel ...). There is EXOS call where you can set EXOS boundary so leave some additional memory for EXOS, since in case of shared segment is allocated, the EXOS boundary (I guess) is set in a way that all the non-used memory can be used within the shared segment by the user (so can't grow by EXOS). As far as I know, shared segment is not needed to be segment $FF, it's possible that already more than 16K of memory is used by EXOS, then the shared segment situation will happen in segment $FE for example. So don't assume register C is $FF in case of shared segment, but use value i register C.

3. There is no free "whole" segment and _also_ the shared segment is already allocated, in this case "NOSEG" error is returned.

Some may think that segment allocation actually can have only two results, allocated segment, or error, but it's not the case as you can see.

Anyway: if you need the workaround to free segment $FF it means that you exhausted all of the segments in the system, and even shared segment _is_ allocated, so you need to free. I guess, if you stop your allocation loop when you got the first video seg (C >= $FC). well, if you need only one video segment of course :) Anyway, I write just too much, I'm sorry :)

What I am not sure about at all: what happens if you allocate ALL segments (including the shared!) and then free all the segments, but not the shared segment. In this case though many segments can be available, _I guess_ EXOS won't work too much, because system segment can't grow downwards (I don't know if EXOS has the ability to "jump" over and continue its tasks at a lower numbered video segment, I guess it can't, since the rule that there is exactly one shared segment or none in the system, but if EXOS would be able to do this, you can also create another shared segment then). Well, EXOS is quite complicated sometimes :) But in a good way, just not so easy to understand. At least, this is _my_ opinion :)
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.August.16. 12:09:33
The problem was in allocate segment part, FF segment was not stored in the table, therefore it was not freed up, you can use the original code just enter an extra LD C,0FFh, EXOS 25 after memory allocation, or here is the modified allocateMemory.
I changed another thing the size of the table was 8, it works only on EP128, I increased to 256 it works an expanded EP to 4MB also, which can not exist in the reality, because there is no EP without ROM :)

Code: [Select]
allocateMemory
              ld de,segment_table+1
              ld hl,segment_table
              ld (hl),0
              ld bc,00ffh
              ldir

ei
              ld hl,segment_table

am1
               exos 24
               ld (hl),c
inc hl
               jr z,am1 ;exit when reach FF segment (EXOS 24 returns with 7fh in A and FF in C, and F is NZ)

am2:
;-----------------------
; for 1st video buffer (in-game)
         ld hl,segment_table
call getVideoSegment
jr nc,resetRoutine
ld (screen1_segment),a

; get 2nd video buffer segment (in-game)
call getVideoSegment
jr nc,resetRoutine
ld (screen2_segment),a

; get additional video buffer segment
call getVideoSegment
jr nc,resetRoutine
ld (additional_video_segment),a

;----

; free unused segments:
ld hl,segment_table
am111:
call free_segment
inc l
jr nz,am111
ret

free_segment
xor a
cp (hl)
ret z
ld c,(hl)
ld (hl),a
exos 25
ret

getVideoSegment:
; numer segmentu zwracany w A
                ld a,$fb
gvs1:
                cp (hl)
                jr c,gvs2
                inc l
                jp nz,gvs1
                ret
gvs2:
                ld a,(hl)
                ld (hl),0
                ret

screen1_segment equ $7fe0
screen2_segment equ $7fe1
additional_video_segment equ $7fe2

additional_normal_segment equ $7fe3


sharesegment_sizes equ $7fe0
sharesegment_table equ $7ff0
segment_table equ $7e00 ;number of max segments is 256
Title: Re: How to begin assembly on Enterprise
Post by: ergoGnomik on 2015.August.16. 13:24:36
Lehet, valakinek kellene írni egy alap keretrendszert amit bárki használhatna, és megfelelne a rendszerbarát programozás követelményeinek. Egy minimális "library"-t ami tartalmazná a tiszta program indítást és leállítást, valamint az alap memória menedzsment (foglalás-felszabadítás) és I/O (betöltés-mentés) hívásokat.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.September.12. 21:19:19
When I'm loading my main file and it takes about 3 segments of data, is it always:
loading into $f8 -> switch page1 to $f9 -> fill it -> switch page1 to $fa -> load the rest
or should I save the segment numbers somewhere, because it could load my data into $fb instead of $fa for example?
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.September.14. 09:31:37
When I'm loading my main file and it takes about 3 segments of data, is it always:
loading into $f8 -> switch page1 to $f9 -> fill it -> switch page1 to $fa -> load the rest
or should I save the segment numbers somewhere, because it could load my data into $fb instead of $fa for example?
It is better to save the segment numbers if you plan to change the pages.
Title: Re: How to begin assembly on Enterprise
Post by: ssr86 on 2015.September.14. 19:30:42
It is better to save the segment numbers if you plan to change the pages.
How do I get their numbers when I'm loading a single big file?
Title: Re: How to begin assembly on Enterprise
Post by: geco on 2015.September.15. 10:32:24
How do I get their numbers when I'm loading a single big file?
If I remember well, of FFh segment 3FFCh contains the page number which originally loaded to B1h page, 3FFDh stores B2h, but if you loded more than 32Kb, then B1h will contain the page which should be at B2h, and on FFh segment 3FFCh contains the page which should be paged in to B1h.
If you use an own loader , it is much simpler, because you page your pages to B1h, B2h,B3h, and just load the whole code, everything will be on the right place.